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

Re: Optional binding

Thread Previous | Thread Next
Larry Wall
March 7, 2005 23:17
Re: Optional binding
Message ID:
On Mon, Mar 07, 2005 at 08:58:44PM -0800, David Storrs wrote:
: Ok, rewrite; is THIS legal?:
: 	sub foo( Int *@a is shape(3) ) { ... }
:  	foo(1, 2, undef);

Yes, since Int can represent undef.

: The sense I'm trying to convey is:
:     "Here is my sub.  It takes three ints."
:     "Here is me calling the sub.  I am giving you only two ints and
:     explicitly telling you [by explicitly passing undef] that I meant
:     to do that so just take it and be quiet."
: To put it another perl5, a sub that was prototyped to take 
: three scalar args will throw an error when you pass only two but will
: accept it if you pass two plus an explicit undef.  On the other hand,
: if it was prototyped to take an array there is no way to tell the
: difference between an explicitly-passed undef and a too-short arg
: list.  How will P6 handle these two scenarios?

Could use "exists", maybe.  Though for an array with shape(3)
it's possible that exists(@a[2]) is always true regardless of the
bound value.  On the other hand, binding an array that is too short
is going to be a type mismatch, so you probably can't get into the
situation of a shaped array being too short to begin with.  It'll
either fail immediately in the case of a normal sub, or it'll
go off looking for something else to MMD to that doesn't violate
any type constraints, and fail if it doesn't fine one.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About