Re: multi method dispatching of optional arguments (further refined)
Luke Palmer wrote: I don't follow your examples. What is the logic behind them? On 9/3/06, Mark Stosberg [EMAIL PROTECTED] wrote: Examples: Arguments (1 2) to signatures 1. (@a?) and 2. (@a) calls 2 For example, I would expect this one to be ambiguous, because the 1. (@a?) sub introduces two different signatures, 1. () and 1. (@a). When given 1 2, 1. (@a) matches as well as 2. (@a), so it is ambiguous. Oops. Yes, I would call that a tie, too. Arguments (@a) to signatures 1. (@a?) and 2. (@a) IS TIE The only difference I can see between this and the one above is @a vs. 1 2, which ought to behave the same way, right? Yes. Note that the variant /with/ the parameter can be considered an exact match, but but the variant /without/ it cannot be considered an exact match. And I expect that if either or both matches the method is considered to be a match. Right? Let's look again at the last example: Arguments () to signatures 1. (@a?) and 2. () calls 2 (@a?) really means () OR (@a). The () implicit in (@a?) is a match, but not an exact match, so the () declared by itself wins, because it /is/ an exact match. Mark
[svn:perl6-synopsis] r11725 - doc/trunk/design/syn
Author: audreyt Date: Sun Sep 3 10:04:00 2006 New Revision: 11725 Modified: doc/trunk/design/syn/S03.pod Log: * S03: Clarify that this: my Dog ($x, $y) really means the same as: my (Dog $x, Dog $y) Modified: doc/trunk/design/syn/S03.pod == --- doc/trunk/design/syn/S03.pod(original) +++ doc/trunk/design/syn/S03.podSun Sep 3 10:04:00 2006 @@ -12,9 +12,9 @@ Maintainer: Larry Wall [EMAIL PROTECTED] Date: 8 Mar 2004 - Last Modified: 16 Aug 2006 + Last Modified: 4 Sep 2006 Number: 3 - Version: 56 + Version: 57 =head1 Changes to Perl 5 operators @@ -1117,6 +1117,12 @@ my ($b, $c); # okay my $b, $c; # wrong: Use of undeclared variable: $c +Types occuring between the declarator and the signature are distributed into +each variable: + +my Dog ($b, $c); +my (Dog $b, Dog $c);# same thing + [XXX the following probably belongs in S06.] The syntax for constructing a CSignature object when the parser isn't already expecting one is:
Unpacking tree node parameters
sub traverse ( BinTree $top ( $left, $right ) ) { ... } LS06/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 [EMAIL PROTECTED] http://gaal.livejournal.com/
Re: multi method dispatching of optional arguments (further refined)
On Sunday 03 September 2006 14:25, Mark Stosberg wrote: Luke Palmer wrote: On 9/3/06, Mark Stosberg [EMAIL PROTECTED] wrote: Note that the variant /with/ the parameter can be considered an exact match, but but the variant /without/ it cannot be considered an exact match. Excuse me for getting into this thread with only minor knowledge about perl6, but will there be MMD based on the *value* of parameters? Like Haskell has. I don't know about a possible syntax, but sometimes it's a very nice way to dispatch to different parts. (I know that that's possible with if statements, but they have a disadvantage: they're not so visually dispatching, if you know what I mean). Regards, Phil