Skip to content

Commit

Permalink
document sequence operator variants ^... and ^...^ ref #3360
Browse files Browse the repository at this point in the history
while here add output to an example for this operator
  • Loading branch information
stoned committed Sep 27, 2020
1 parent a88182c commit c8939e9
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions doc/Language/operators.pod6
Expand Up @@ -65,7 +65,7 @@ assigned to that level (column labeled C<A>), and some exemplary operators
R | Item assignment | = => \+= -= **= xx=
L | Loose unary | so not
X | Comma operator | , :
X | List infix | Z minmax X X~ X* Xeqv ... … ...^ …^
X | List infix | Z minmax X X~ X* Xeqv ... … ...^ …^ ^... ^… ^...^ ^…^
R | List prefix | print push say die map substr ... [\+] [*] any Z=
X | Loose and | and andthen notandthen
X | Loose or | or xor orelse
Expand Down Expand Up @@ -3089,15 +3089,22 @@ lists are replaced by the value from applying the operator to the list:
# produces (1a9 1b9 1c9 2a9 2b9 2c9 3a9 3b9 3c9)
=head2 infix C«...»
X<|...,operators>X<|...^,operators>X<|…,operators>X<|…^,operators>
X<|...,operators>X<|...^,operators>X<|^...,operators>X<|^...^,operators>
X<|…,operators>X<|…^,operators>X<|^…,operators>X<|^…^,operators>
X<|lazy list,…>
multi sub infix:<...>(**@) is assoc<list>
multi sub infix:<...^>(**@) is assoc<list>
multi sub infix:<^...>(**@) is assoc<list>
multi sub infix:<^...^>(**@) is assoc<list>
The X<sequence operator>, which can be written either as C<...> or as
C<> (with variants C<...^> and C<…^>) will produce (possibly lazy)
generic sequences on demand.
C<> (with variants C<...^>, C<^...>, C<^...^>, C<…^>, C<^…> and C<^…^>)
will produce (possibly lazy) generic sequences on demand.
Note: the sequence operator variants C<^...>, C<^...^>, C<^…> and
C<^…^> have been available in Rakudo compiler starting from 2020.05
release.
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
Expand Down Expand Up @@ -3148,11 +3155,12 @@ knows about arithmetic and geometric sequences.
If the endpoint is not C<*>, it's smartmatched against each generated
element and the sequence is terminated when the smartmatch succeeded.
For the C<...> operator, the final element is included, for the C<...^>
operator it's excluded.
and the C<^...^> operators it's excluded.
This allows you to write
say 1, 1, * + * ...^ *>= 100;
# OUTPUT: «(1 1 2 3 5 8 13 21 34 55 89)␤»
to generate all Fibonacci numbers up to but excluding 100.
Expand All @@ -3163,6 +3171,11 @@ well, so they are also checked against the endpoint:
say 1, 2, 4, 8, 16 ... $end;
# OUTPUT: «(1 2 4)␤»
The C<^...> and C<^...^> operators excludes the initial element.
say 1, 2, 4 ^... 128; # OUTPUT: «(2 4 8 16 32 64 128)␤»
say 1, 2, 4 ^...^ 128; # OUTPUT: «(2 4 8 16 32 64)␤»
=head1 List prefix precedence
X<|list =>
Expand Down

0 comments on commit c8939e9

Please sign in to comment.