develooper Front page | perl.perl6.language | Postings from April 2008

Returning Arrays?

Thread Next
From:
John M. Dlugosz
Date:
April 16, 2008 01:49
Subject:
Returning Arrays?
How do you declare a function that returns an array?  Something like

    sub foo (blah) is Array of X { ... }

seems right, but it has two problems.  First is a real problem, and is a 
mistake seen a lot in C# and the .NET framework.  A concrete type is 
used when it should be an interface.  What if the function wants to use 
a List or Seq or some bizzare tied thing of its own?  Defining it as


    sub foo (blah) is Positional of X { ... }

is not as snappy, and I don't think it will catch on.  (I'm still 
wondering whether Lists and Seq's are Positional anyway, merely lazy 
about it)

So that brings me to the second problem.  For parameters, it's no 
problem because people just use the @ sigil and don't think about 
containers.  So how do I do that with the return value?  I don't name 
the return value, so there is no place to put the sigil.

   sub foo (blah) is X @*

perhaps?   I seem to recall seeing sigils in a signature without names, 
but now I can't remember where.

--John

Thread Next


Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About