Hi,

Am 22.07.2010 17:18, schrieb Jon Lang:
When I last reviewed the writeup for the series operators, I noticed two issues:

First, why is the RHS argument a list?  You only ever use the first
element of it; so why don't you just reference a single value?

The idea is that you can continue series:

  1, 2, 3 ... 10,
  20, 30, ... 100,

etc.

Second, I'm trying to think of a simple and intuitive way to write up
a series expression for:

    triangle numbers: 0, 1, 3, 6, 10, 15, 21, etc.

Use the right tool for the right job:

17:32 <@moritz_> rakudo: say ~[\+] 0..6
17:32 <+p6eval> rakudo 925a9b: OUTPUT«0 1 3 6 10 15 21␤»

    square numbers: 0, 1, 4, 9, 16, 25, 36, etc.

17:34 <@moritz_> rakudo: say ~(1..10).map(* ** 2)
17:35 <+p6eval> rakudo 925a9b: OUTPUT«1 4 9 16 25 36 49 64 81 100␤»

Or with a bit of a math trick:

17:36 <@moritz_> rakudo: say ~(1, { $_ + 2 * .sqrt + 1} ... 100)
17:36 <+p6eval> rakudo 925a9b: OUTPUT«1 4 9 16 25 36 49 64 81 100␤»


    factorials: 1, 1, 2, 6, 24, 120, 720, 5040, etc.

17:33 <@pmichaud> rakudo:  say ~[\*] 1..6
17:33 <+p6eval> rakudo 925a9b: OUTPUT«1 2 6 24 120 720␤»

The difficulty that I'm running into is that there's no reasonably
straightforward way of computing a given term solely from the previous
one or two items in the list.

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.

The series operator is intented to be a relatively powerful (and yet simple to use) tool to generate some common series. For other cases, the full power of Turing-complete Perl 6 stands at your disposal (to which you probably need to revert when you want both index *and* previously computed values, *and* can't rely on other operator magic).

Cheers,
Moritz

Reply via email to