Hi,
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.
Yep.
> 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.
Right, you name it: you get *pairs* out of the array, not named
parameters. Under the proposal, a Pair object doesn't have any special
magic -- it's simply
class Pair { has $.key; has $.value is rw }
Thus:
my @array = (42, "hi", (a => 23));
foo [EMAIL PROTECTED]; # same as
foo 42, "hi", (a => 23); # three positional params (Int, Str, Pair)
> It's worth pointing out that perl does know the list of declared named
> args, though that may not be enough. If the pair.key matches an
> expected arg, then splat should collapse it for sure. If it doesn't
> match...I dunno.
But that's exactly the problem. You shouldn't have to worry about any
special magic when dealing with [EMAIL PROTECTED] Consider:
sub foo ($a, $b, $c, ?$d) {...}
my @array = (1, 2, (key => "value"));
foo [EMAIL PROTECTED]; # fine, no problem, $c will receive (key => "value")
my @array = (1, 2, (d => "value"));
foo [EMAIL PROTECTED]; # oops! $a = 1, $d = "value"
# "Required argument 'c' not given!"
> Is there a list() operator for converting hashes into lists of pairs?
my @array_of_pairs = %hash; # short for
my @array_of_pairs = list %hash;
--Ingo