How to pass repetition of an unflattened array to shorthand in Perl 6?

I try to pass an xx re-array to the reduction function [X ~], but find that the array is smoothed. I searched for online docs and stack overflows but didn't find anything. Unfortunately, my knowledge of Perl 6 is rather rudimentary (although I know Perl 5 well).

[X~](<1 2>, <1 2>)    # 11 12 21 22 (WHAT I WANT)
[X~](<1 2> xx 2)      # 1 2 1 2 (NOT WHAT I WANT)
[X~](<1 2> xx 2).tree # 1 2 1 2
[X~](<1 2>.tree xx 2) # 1 2 1 2

Looking at .perl dumps, I don’t have much coverage:

(<1 2>, <1 2>).perl    # (("1", "2"), ("1", "2"))
(<1 2> xx 2).perl      # (("1", "2"), ("1", "2")).list
(<1 2> xx 2).tree.perl # ("1", "2"; "1", "2").item

I am using rakudo-star-2014.12.1-parrot.msi.

+4
source share
1 answer

Assuming you also want your code to work with arrays repeating more than two times, the workaround I came up with is reading

(<1 2> xx 2).tree.reduce({ @^a X~ @^b })

, List/Parcel 1 - .

(cf ), , 6.0 .

1 , , :

(<1 2>, <1 2>).WHAT    # (Parcel)
(<1 2> xx 2).WHAT      # (List)
(<1 2> xx 2).tree.WHAT # (LoL)

- .

+4

All Articles