HaloO,
John M. Dlugosz wrote:
How do you declare a function that returns an array? Something like
sub foo (blah) is Array of X { ... }
The 'is' there is your invention, isn't it? The synopsis
require 'of' or 'returns' depending if you want to specify
the outer and/or inner type. The 'is' keyword would be used as
sub foo () is Code of Array of X {...}
sub foo () is Code[Array[X]] {...} # same thing
In general the of keyword instanciates parametric types just like
the direct indexing of typenames with []. The only unspecced thing
is the variance of ::Foo[::Bar] with respect to ::Bar.
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 { ... }
What's so bad about 'sub foo ( --> 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)
I would thing that Seq does Positional in an immutable way.
That is in &postcircumfix:<[ ]>:(Positional $seq: Int *@@slice --> ::T)
::T is always an rvalue.
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 @*
Should be 'sub foo( --> X *@)' or 'our X *@ sub foo()'. In case that
this doesn't parse 'our :(X *@) sub foo()' should.
perhaps? I seem to recall seeing sigils in a signature without names,
but now I can't remember where.
Same here. Should be in the synopsis somewhere.
Regards, TSa.
--
"The unavoidable price of reliability is simplicity"
-- C.A.R. Hoare