Hi, Stuart Cook wrote: > On 11/10/05, Austin Hastings <[EMAIL PROTECTED]> wrote: >> A rule that says >> "splatting >> a list coerces all pairs into named args" works just fine. The >> corresponding rule, "accessing the parameters to your sub as a list >> (not using *%args) coerces all named args to pairs". Presto! >> Reversible, etc. > > 2) > What if the list contains pairs, but you want to pass them as > positionals? What if it might contain pairs, but you're not sure? > What if you introduce a new named parameter (or change a parameter > name), and what you thought was a positional pair now becomes a named > arg? > > Your suggestion would involve re-introducing some of the 'magic' that > real experience suggests we should be trying desperately to get away > from.
Exactly. I'd like to add that, under the proposal, you always know what things are passed how, only by looking for a "*". foo $var; # always positionally, even if $var isa Pair foo *$pair; # always named foo [EMAIL PROTECTED]; # always positionally foo *%hash; # always named (hash keys taken as parameter names) Previously, you wasn't able to know whether you passed something positionally or by name: sub bar ($x) { grtz $x } bar 42; # 42 passed to &grtz positionally bar a => 42; # either the pair (a => 42) passed to &grtz # positionally or the number 42 passed by name Under the new proposal, "grtz $x" always passes $x positionally. You don't need &grtz's signature, nor do you need to know $x's type (is $x a Pair?). Compare this with the old semantics: grtz $x; # $x is not a Pair? ==> $x passed positionally # else ==> # &grtz expects a Pair as its first positional parameter? # ==> $x passed positionally # else ==> # &grtz's signature lists a parameter named $x.key? # ==> $x.value passed by name # else # ==> $x passed positionally > And look, if you really wanted to, you could define your own > splat-style operator that works exactly as you describe. But I don't > think it should be the default. Right. Under the proposal, you can -- *if you want to* -- use pairs stuffed in arrays as named arguments: foo *hash(@array_of_pairs); # @array_of_pairs's pairs used as named args foo [EMAIL PROTECTED]; # @array_of_pairs's pairs used positionally But if we made [EMAIL PROTECTED] mean that... * [EMAIL PROTECTED]'s pairs are always taken as named arguments, there wouldn't be a simple way to pass pairs positionally. * [EMAIL PROTECTED]'s pairs are always taken as pairs, there wouldn't be a simple way to use the pairs as named arguments. * [EMAIL PROTECTED]'s pairs are taken as pairs or named arguments, depending on the called subroutine (does it accept named params? Do some parameters specifically want a Pair? etc.), we'd introduce non-local non-determinism to a quite important part of the language. --Ingo