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

* 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

Reply via email to