routine ...

Documentation for routine ... assembled from the following types:

language documentation Operators

From Operators

(Operators) infix ...

multi sub infix:<...>(**@) is assoc<list>
multi sub infix:<...^>(**@) is assoc<list>

The sequence operator, which can be written either as ... or as (with variants ...^ and …^) will produce (possibly lazy) generic sequences on demand.

The left-hand side will always include the initial elements; it may include a generator too (after the first element or elements). The right-hand side will have an endpoint, which can be Inf or * for "infinite" lists (that is, lazy lists whose elements are only produced on demand), an expression which will end the sequence when True, or other elements such as Junctions.

The sequence operator invokes the generator with as many arguments as necessary. The arguments are taken from the initial elements and the already generated elements. The default generator is *.succ or *.pred, depending on how the end points compare:

say 1 ... 4;        # OUTPUT: «(1 2 3 4)␤» 
say 4 ... 1;        # OUTPUT: «(4 3 2 1)␤» 
say 'a' ... 'e';    # OUTPUT: «(a b c d e)␤» 
say 'e' ... 'a';    # OUTPUT: «(e d c b a)␤»

An endpoint of * (Whatever), Inf or generates on demand an infinite sequence, with a default generator of *.succ

say (1 ... *)[^5];  # OUTPUT: «(1 2 3 4 5)␤»

Custom generators need to be the last element of the list before the '...' operator. This one takes two arguments, and generates the eight first Fibonacci numbers

say (11-> $a$b { $a + $b } ... *)[^8]; # OUTPUT: «(1 1 2 3 5 8 13 21)␤» 
# same but shorter 
say (11* + * ... *)[^8];                 # OUTPUT: «(1 1 2 3 5 8 13 21)␤» 

Of course the generator can also take only one argument.

say 5{ $_ * 2 } ... 40;                # OUTPUT: «5 10 20 40␤»

There must be at least as many initial elements as arguments to the generator.

Without a generator and with more than one initial element and all initial elements numeric, the sequence operator tries to deduce the generator. It knows about arithmetic and geometric sequences.

say 246 ... 12;     # OUTPUT: «(2 4 6 8 10 12)␤» 
say 124 ... 32;     # OUTPUT: «(1 2 4 8 16 32)␤»

If the endpoint is not *, it's smartmatched against each generated element and the sequence is terminated when the smartmatch succeeded. For the ... operator, the final element is included, for the ...^ operator it's excluded.

This allows you to write

say 11* + * ...^ *>= 100;

to generate all Fibonacci numbers up to but excluding 100.

The ... operators consider the initial values as "generated elements" as well, so they are also checked against the endpoint:

my $end = 4;
say 124816 ... $end;
# OUTPUT: «(1 2 4)␤»

language documentation Operators

From Operators

(Operators) listop ...

Called the yada, yada, yada operator or stub operator, if it's the only statement in a routine or type, it marks that routine or type as a stub (which is significant in the context of pre-declaring types and composing roles).

If the ... statement is executed, it calls fail, with the default message Stub code executed.