L<S06/"Unpacking tree node parameters"> has two infelicities I wanted to
fix with a patch. The first is that this style of unpacking is "really"
syntactically a Signature, but most the examples in this section
abbreviate out the optional colon. (The above is more formally spelled:
sub traverse ( BinTree $top :( $left, $right ) ) { ... } # or even...
sub traverse :( BinTree $top :( $left, $right ) ) { ... }
I'm ignoring the final version here.)
The paragraph explaining this point, however, uses for its justification
an example from the variable declaration world:
> You may omit the top variable if you prefix the parentheses with a colon
> to indicate a signature. Otherwise you must at least put the sigil of
> the variable, or we can't correctly differentiate:
> my Dog ($fido, $spot) := twodogs(); # list of two dogs
> my Dog $ ($fido, $spot) := twodogs(); # one twodog object
> my Dog :($fido, $spot) := twodogs(); # one twodog object
Unless I'm mistaken, this doesn't cast back to subroutine signature land
very well:
sub f1 (Dog ($fido, $spot)) { ... }
sub f2 (Dog $ ($fido, $spot)) { ... }
sub f3 (Dog :($fido, $spot)) { ... }
f1(twodogs()); # really a list of two dogs?
f2(twodogs()); # one twodog object
f3(twodogs()); # one twodog object
Unless Audrey's latest S03 patch pertains here as well, and Dog
distributes; in that case it would be as if the programmer had written
sub f1 ([Dog $fido, Dog $spot]) { ... }
as described in the preceding section, "Unpacking array parameters". If
this is *not* the case, then f1 is not ambiguous!
Please clarify, so I can clean up the confusing paragraph and introduce
the optionality of the colon less jarringly.
--
Gaal Yahas <ga...@forum2.org>
http://gaal.livejournal.com/
> Unless I'm mistaken, this doesn't cast back to subroutine signature
> land
> very well:
>
> sub f1 (Dog ($fido, $spot)) { ... }
> sub f2 (Dog $ ($fido, $spot)) { ... }
> sub f3 (Dog :($fido, $spot)) { ... }
>
Correct.
> Unless Audrey's latest S03 patch pertains here as well, and Dog
> distributes; in that case it would be as if the programmer had written
>
> sub f1 ([Dog $fido, Dog $spot]) { ... }
Yes, except there's no [] there; it's two positional parameters.
> as described in the preceding section, "Unpacking array
> parameters". If
> this is *not* the case, then f1 is not ambiguous!
TimToady++ just confirmed on IRC that it is indeed the case.
> Please clarify, so I can clean up the confusing paragraph and
> introduce
> the optionality of the colon less jarringly.
Woot! :-)
Audrey