Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Revisit infix ...
- mention Seq type
- introduce all its variants, with examples
- consider variants with an initial caret in wording
  • Loading branch information
stoned committed Sep 27, 2020
1 parent c8939e9 commit a2e77f0
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions doc/Language/operators.pod6
Expand Up @@ -3099,18 +3099,26 @@ X<|lazy list,…>
multi sub infix:<^...^>(**@) is assoc<list>
The X<sequence operator>, which can be written either as C<...> or as
C<> (with variants C<...^>, C<^...>, C<^...^>, C<…^>, 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. Such sequences
are of the L«C<Seq>|/type/Seq» type.
Note: the sequence operator variants C<^...>, C<^...^>, C<^…> and
C<^…^> have been available in Rakudo compiler starting from 2020.05
release.
The variants of the operator with an initial caret, C<^...>, C<^...^>,
C<^…> and C<^…^>, produce sequences that do not contain the initial
element.
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
The variants of the operator with a final caret, C<...^>, C<^...^>,
C<…^> and C<^…^>, produce sequences that do not contain the final
element.
Note: the variants C<^...>, C<^...^>, C<^…> and C<^…^> have been
available in Rakudo compiler starting from 2020.05 release.
The left-hand side of the operator specify the initial elements; it may include a
generator after the first element or elements. The right-hand side will
have an endpoint, which can be C<Inf> or C<*> for "infinite" lists (that is,
I<lazy> lists whose elements are only produced on demand), an expression which
will end the sequence when C<True>, or other elements such as
will end the sequence when C<True>, or other terms such as
L<Junctions|/type/Junction>.
The sequence operator invokes the generator with as many arguments as necessary.
Expand All @@ -3120,6 +3128,9 @@ C<*.>L<pred|/routine/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 1 ^... 4; # OUTPUT: «(2 3 4)␤»
say 1 ...^ 4; # OUTPUT: «(1 2 3)␤»
say 1 ^...^ 4; # OUTPUT: «(2 3)␤»
say 'a' ... 'e'; # OUTPUT: «(a b c d e)␤»
say 'e' ... 'a'; # OUTPUT: «(e d c b a)␤»
Expand Down Expand Up @@ -3151,11 +3162,13 @@ knows about arithmetic and geometric sequences.
say 2, 4, 6 ... 12; # OUTPUT: «(2 4 6 8 10 12)␤»
say 1, 2, 4 ... 32; # OUTPUT: «(1 2 4 8 16 32)␤»
say 1, 2, 4 ^... 32; # OUTPUT: «(2 4 8 16 32)␤»
say 1, 2, 4 ^...^ 32; # OUTPUT: «(2 4 8 16)␤»
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<...^>
and the C<^...^> operators it's excluded.
The final element is included in the sequence according to the operator
variant used.
This allows you to write
Expand All @@ -3171,11 +3184,6 @@ 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 a2e77f0

Please sign in to comment.