Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assignment to nested lists in Perl 6

Tags:

raku

I supposed, the result should be 1, 2, 3.

> my ($a, $b, $c)
> (($a, $b), $c) = ((1, 2), 3)
(((1 2) 3) (Any))
> $a, $b, $c
((1 2) 3 (Any))

What's wrong here?

like image 653
Eugene Barsky Avatar asked May 07 '18 19:05

Eugene Barsky


1 Answers

There's nothing wrong (that is, ordinary assignment in P6 is designed to do as it has done) but at a guess you were hoping that making the structure on the two sides the same would result in $a getting 1, $b getting 2 and $c getting 3.

For that, you want "binding assignment" (aka just "binding"), not ordinary assignment:

my ($a, $b, $c);
:(($a, $b), $c) := ((1, 2), 3);

Note the colon before the list on the left, making it a signature literal, and the colon before the =, making it a binding operation.

like image 172
raiph Avatar answered Oct 13 '22 00:10

raiph