On Thu, Jul 22, 2010 at 9:25 AM, Aaron Sherman <a...@ajs.com> wrote: > On Thu, Jul 22, 2010 at 11:41 AM, Moritz Lenz <mor...@faui2k3.org> wrote: >> The difficulty you're running into is that you're trying to use the wrong >> tool for the job. Just don't use the series operator when it's not easy to >> use. Perl 6 has other mechanism too, which are better suited for these >> particular problems. > > In general, I'd agree. However, there is something to be said for the > underlying question: is there a way to get at the iteration index from the > lambda in a series? It seems like that's something that it's not > unreasonable to want. > > I also think it's doable without a special tool: > > 0, { state $i = 1; $^a + $i++ } ... * > > That should work, no? Granted, state doesn't seem to work in Rakudo, unless > I'm mis-understanding how to use it, but that's the idea.
Kludgey; but possibly doable. Another possibility that might work would be to use the default list parameter to count the previous elements: +...@_. That would be notationally more compact, but would also potentially wreak havoc on the computational efficiency of the model; and while you could get the index number from it, it wouldn't always be quite as simple as counting its elements. But what I'd really like to see would be for the index to be passed into the step function via a named parameter. Yes, it would be a special tool; but it would be much more in keeping with the "keep simple things easy" philosophy that Perl 6 tends to promote: 0, { $^a + $:i } ... * # series of triangle numbers 0, { $^a + (2 * $:i - 1) } ... * # series of square numbers { $:i ** 2 } ... * # series of square numbers 1, { $^a * $:i } ... * # series of factorials -- Jonathan "Dataweaver" Lang