develooper Front page | perl.perl6.language | Postings from May 2005

Re: foo(1: 2: 3: 4:) ?

Thread Previous | Thread Next
From:
Damian Conway
Date:
May 22, 2005 18:05
Subject:
Re: foo(1: 2: 3: 4:) ?
Message ID:
42912C63.7010208@conway.org
Autrijus Tang wrote:

> Hmm, Warnocked?  I'll assume this is sane, until told otherwise, then. :)

Darn. I was hoping that Larry would field this one. In his absence, I'll take 
a swing at it. The usual all(any(@Larry), none($Larry)) caveats apply.


> So I'm finally starting to implement multi-level invocants in MMDs.
> I'd like to sanity check some cases first, though.
> 
> Are these two assumed to be identical?
> 
>     multi sub foo ($x, $y)
>     multi sub foo ($x, $y : )

Yes. The rule is that every parameter of a multi, up to the last colon (if 
any), is an invocant.


> But these two are _not_ identical?
> 
>     multi sub foo ($x : $y : $z)
>     multi sub foo ($x : $y : $z : )

Correct. Both dispatch first on their $x parameter. Then (because the types of 
the two $x parameters are identical (i.e. Any)), both dispatch on their $y 
parameters. Again, both parameter types are identical, so the third-level 
invocants are used as a second-order tie-breaker. The first multisub doesn't 
*have* a  third-level invocant, so it loses immediately. The type of the 
second multisub's third-level invocant is Any, so it matches at zero cost and 
is invoked.

> Are multiple colons usable in invocation?

No.


> S12 says all the following cases "come out to the same thing":
> 
>     $handle.close	# 1
>     close($handle)	# 2
>     close $handle:	# 3
>     close $handle	# 4
> 
> Does it mean that during invocation, when there is no colons and
> no dots, an implicit colon is added at the end, making all arguments
> same-level invocants and subject to MMD? 

This is only true if there is exactly one argument and there's a multi of the 
appropriate name in scope at the time.


> That is, these are identical:
> 
>     foo($a, $b)
>     foo($a, $b : )

No, the second is an error.


> But these two are _not_:
> 
>     foo($a : $b : $c)
>     foo($a : $b : $c : )

Well, they're both errors, so whether they're identical becomes a 
philosophical problem. ;-)

Damian

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About