Am 22.03.2012 17:07, schrieb Bruce Gray:
I have run into the same need for something like :index, while
playing with RosettaCode tasks like "Continued_fraction".

If you want the index, don't use series. It's easy enough to access the array elements yourself. You can do something like

my @a := (1..*).map: -> $i {
    $i ** 2 + @a[$i - 1] // 0;
};

to access previous elements. You can even use 'last' inside the map block to get out of the loop.


Well, it works in Niecza. It does not (yet) work in Rakudo:
15:25 <Util> perl6: my @squares := 0, (-> *@a { @a.elems ** 2 }) ... *;
say ~@squares[^11];
15:25 <p6eval> ..niecza v15-4-g1f35f89: OUTPUT<<0 1 4 9 16 25 36 49 64
81 100NL>>
15:25 <p6eval> ..rakudo 1a468d: OUTPUT<<0 0 0 0 0 0 0 0 0 0 0NL>>

higher-arity sequences are a known regression in rakudo, S03-sequence/limit-arity-2-or-more.t currently isn't run.


After writing all the above, it occurred to me that the use of @_ should
implicitly define a closure as slurpy/n-ary.

It shouldn't only, it does already (in all <rakudo pugs niecza>).
The future is already here, it's just unevenly distributed.


Cheers,
Moritz

Reply via email to