Operators

The sequence operator ...

Full

Generate a series by inferring the step, or by giving a closure — even infinite ones.

The sequence operator ... builds a list from a starting point to an endpoint, inferring the pattern from the leading elements. Give it a closure instead of a literal step and it can produce any series, including unbounded ones.

Inferred arithmetic and geometric steps #

From two or more leading terms, ... infers a constant difference (arithmetic) or ratio (geometric).

say (2, 4 ... 10);
say (1 ... 5);
say (10 ... 1);
Output
(2 4 6 8 10)
(1 2 3 4 5)
(10 9 8 7 6 5 4 3 2 1)

A ratio between the first terms gives a geometric sequence:

say (1, 2, 4 ... 64);
Output
(1 2 4 8 16 32 64)

A closure as the generator #

The right-hand generator can be a closure of the previous terms. * + * sums the last two — the Fibonacci rule — and a * endpoint means "go forever" (taken lazily).

say (1, 1, * + * ... *)[^10];
Output
(1 1 2 3 5 8 13 21 34 55)

Notes #