On May 22, 2009 06:55:49 pm John M. Dlugosz wrote:
> Please take a look at
> <http://www.dlugosz.com/Perl6/web/passing_examples.html>.
I think that in your "Example 1", that you may be making too making too much
of a distinction between "$a" and "@a". That is:
sub f2(@y) {...}
has exactly the same signature as
sub f2($x is Array) {...}
In other words, they both take a single argument that must be of type Array.
Hence, @y and $x work the same "beneath the surface" and there is no extra
level of indirection.
Now that we are viewing parameters as providing constraints rather than
contexts, we get a different view on your "Example 2". I made your example
more concrete and ran it through rakudo, yielding:
> sub f1 ($x) {say $x.WHAT}; f1(Nil);
Nil()
> sub f2 (@y) {say @y.WHAT; say +...@y}; f2(Nil);
Array()
1
>
See, no problems with f2().
Regards,
Henry
> I started working through how the detailed behavior of the Capture and
> passing rules need to work, and I ran into something that startled me.
> There's no examples in S06 of formal parameters, other than the special
> *...@slurp form, that is declared with a sigil other than a $. For example,
>
> sub f1 ($x, @y, @z) { ... }
>
> Before I get any farther with this line of thought, I want to know if
> I'm missing something important.
>
> Thanks,
> --John
--
Henry Baragar
Instantiated Software
416-907-8454 x42