Ingo Blechschmidt wrote: >Hi, > >while fixing bugs for the imminent Pugs 6.2.10 release, we ran into >several issues with magical pairs (pairs which unexpectedly participate >in named binding) again. Based on Luke's "Demagicalizing pairs" thread >[1], #perl6 refined the exact semantics [2]. > >The proposed changes are: > >* "(key => $value)" (with the parens) is always a positionally passed > Pair object. "key => $value" (without the parens) is a named > parameter: > > sub foo ($a) {...} > > foo(a => 42); # named parameter "a", $a will be 42 > foo(:a(42)); # same > > > > foo((a => 42)); # positional parameter (a pair), > # $a will be the Pair (a => 42) > foo((:a(42))); # same > > >
What about whitespace? foo (a => 42); # Note space Is that the first case (subcall with named arg) or the second case (sub with positional pair)? >* Passing a variable containing a Pair is always passed positionally: > > my $pair = (a => 42); # or :a(42) > > foo($pair); # positional parameter, $a will be the Pair (a => 42) > >* Unary "*" makes a normal pair variable participate in named binding: > > foo(*$pair); # named parameter "a", $a will be 42 > >* Same for hashes: > > my %hash = (a => 1, b => 2, c => 3); > > foo(%hash); # positional parameter, $a will be \%hash > > foo(*%hash); # three named parameters > >Opinions? > > >--Ingo > >[1] http://article.gmane.org/gmane.comp.lang.perl.perl6.language/4778/ >[2] >http://colabti.de/irclogger/irclogger_log/perl6?date=2005-10-09,Sun&sel=528#l830 > > > What's the most complete way to get the sub's arguments? That is, for a sub that takes positional, optional, named, and variadic (*) arguments, what's the best mechanism for grabbing the entire call? Your reply to Uri: > Uri Guttman wrote: >> but what about lists and arrays? >> >> my @z = ( 'a', 1 ) ; >> foo( @z ) # $a = [ 'a', 1 ] ?? > > > Yep. Suggests that I cannot pass along parameters in the usual way: sub foo(...) { bar(@_); } Does that work if I code it as bar @_; (which is huffmanly, but hardly intuitive). =Austin