Dave Whipp wrote:
> Austin Hastings wrote:
>> How about "perl should DWIM"? In this case, I'm with Juerd: splat
>> should pretend that my array is a series of args.
>> So if I say:
>> foo [EMAIL PROTECTED];
>> or if I say:
>> foo([EMAIL PROTECTED]);
>> I still mean the same thing: shuck the array and get those args out
>> here, even the pairs.
> The trouble is, an array doesn't contain enough information:
> foo( (a=>1), b=>2 );
> @args = ( (a=>1), b=>2 );
> foo( [EMAIL PROTECTED] );
my @args = ( (a => 1), b => 2 ); # is sugar for
my @args = ( (a => 1), (b => 2) );
# We can't stuff named arguments into an array, only pairs.
# Named arguments are neither objects nor some other data type,
# they're purely syntactical.
> If we have an arglist ctor, then we could have
> @args = arglist( (a=>1), b=>2 );
> foo( [EMAIL PROTECTED]);
> say @args.perl
> ## (
> ## (a=>1) but is_positional,
> ## (b=>2) but is_named,
> ## )
> but without such a constructor, it would be difficult to DWIM
Yep, see Luke's tuple proposal :
my $tuple = ( (a => 1), b => 2 );
foo *$tuple; # same as
foo( (a => 1), b => 2 ); # one positional argument (a Pair) and
# the named parameter "b"