From c8939e91df8f4cec4ce320c855843f1a0f639231 Mon Sep 17 00:00:00 2001 From: Stoned Elipot Date: Sat, 19 Sep 2020 22:48:18 +0200 Subject: [PATCH] document sequence operator variants ^... and ^...^ ref #3360 while here add output to an example for this operator --- doc/Language/operators.pod6 | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/doc/Language/operators.pod6 b/doc/Language/operators.pod6 index d02795d5c..d3c1ea728 100644 --- a/doc/Language/operators.pod6 +++ b/doc/Language/operators.pod6 @@ -65,7 +65,7 @@ assigned to that level (column labeled C), 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 @@ -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 multi sub infix:<...^>(**@) is assoc + multi sub infix:<^...>(**@) is assoc + multi sub infix:<^...^>(**@) is assoc The X, 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 @@ -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. @@ -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 =>