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

Re: Optional binding

Thread Previous | Thread Next
From:
David Storrs
Date:
March 7, 2005 20:58
Subject:
Re: Optional binding
Message ID:
20050308045844.GA90638@megazone.bigpanda.com
On Mon, Mar 07, 2005 at 07:50:47PM -0800, Larry Wall wrote:
> On Mon, Mar 07, 2005 at 05:37:53PM -0800, David Storrs wrote:
> : On Mon, Mar 07, 2005 at 04:58:29PM -0800, Larry Wall wrote:
> : Is
> : there is then any way to explicitly leave off an element.  Can I do
> : this:
> : 
> : 	sub foo( Int @a is shape(3) ) { ... }
> : 	foo(1, 2, undef);
> 
> That's illegal unless you either * the @a or [] the list.  

Argh.  My bad, I meant to * the @a.  Ok, rewrite; is THIS legal?:

	sub foo( Int *@a is shape(3) ) { ... }
 	foo(1, 2, 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 way...in 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?

--Dks

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