Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The R metaoperator apparently reverses lists too

Tags:

raku

The R metaop should reverse the effect of the operator it applies too. However, it does apparently a bit more than that, reversing lists if that's what it's applied to:

my @crossed = <1 2 3> Z <4 5 6>; # [(1 4) (2 5) (3 6)]
say [RZ] @crossed; # ((3 2 1) (6 5 4))

What I would like to obtain is the original lists, however, the result is reversed. Is there something I'm missing here?

like image 751
jjmerelo Avatar asked Aug 07 '19 20:08

jjmerelo


2 Answers

R metaop does not reverse the effect of the operator. Instead it reverses the order of the operands, i.e.

$lhs <op> $rhs === $rhs R<op> $lhs

Or in your example the semantics are like this:

[RZ] [<1 4>, <2 5>, <3 6>] #is the same as [Z] [<3 6>, <2 5>, <1 4>]
like image 162
gmoshkin Avatar answered Nov 19 '22 16:11

gmoshkin


Z itself does already create the original lists. No need for R Operator.

my @crossed = <1 2 3> Z <4 5 6>; # [(1 4) (2 5) (3 6)]
say [Z] @crossed; #((1 2 3) (4 5 6))
like image 41
LuVa Avatar answered Nov 19 '22 16:11

LuVa