Hi, quoting http://dev.perl.org/perl6/synopsis/S06.html: > Pairs can be used as lvalues. The value of the pair is the > recipient of the assignment: > > (key => $var) = "value"; > > When binding pairs, names can be used to "match up" lvalues > and rvalues: > > (who => $name, why => $reason) := (why => $because, who => "me");
that's really convenient, but what will the following code do? my $x = (a => 42); # $x is a Pair. $x = 13; # Is $x now the Pair (a => 13) or # the Int 13? When executing the second line, $x is a Pair. And it is used as a lvalue. So, according to S06, the assignment will only change the value of the Pair, not the Pair itself. But I doubt this is what most programmers will expect -- example: sub foo (Any $x) { $x = 13; # Won't always make $x an Int. ...; } my $pair = (a => 42); foo($pair); So, does this Pairs-as-lvalue rule only affect "real syntax-Pairs"? If not, what would the sub unpairify in the following code have to look like? my $x = (a => 42); unpairify($x, 13); # $x is now the Int 13. sub unpairify (Any $x is rw, Int $num) { ...; # fill in please } --Ingo -- Linux, the choice of a GNU | self-reference, n. - See self-reference generation on a dual AMD- | Athlon! |