Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Unpacking tree node parameters

7 views
Skip to first unread message

Gaal Yahas

unread,
Sep 3, 2006, 2:11:14 PM9/3/06
to perl6-l...@perl.org
> sub traverse ( BinTree $top ( $left, $right ) ) { ... }

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/

Audrey Tang

unread,
Sep 13, 2006, 12:18:14 PM9/13/06
to Gaal Yahas, perl6-l...@perl.org

在 Sep 4, 2006 2:11 AM 時,Gaal Yahas 寫到:

> 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

0 new messages