@@ -2387,13 +2387,13 @@ list:
2387
2387
say 100, 200 Z+ 42, 23; # OUTPUT: «(142 223)»
2388
2388
say 1..3 Z~ <a b c> Z~ 'x' xx 3; # OUTPUT: «(1ax 2bx 3cx)»
2389
2389
2390
+ X < |cross product operator >
2390
2391
= head2 infix C « X »
2391
2392
2392
2393
sub infix:<X>(**@lists --> List:D)
2393
2394
2394
- Creates a cross product from all the lists, order so that the rightmost
2395
- elements vary most rapidly:X < |cross product operator >
2396
-
2395
+ Creates a cross product from all the lists, ordered so that the
2396
+ rightmost elements vary most rapidly:
2397
2397
1..3 X <a b c> X 9
2398
2398
# produces ((1 a 9) (1 b 9) (1 c 9)
2399
2399
# (2 a 9) (2 b 9) (2 c 9)
@@ -2411,41 +2411,49 @@ X<|...,operators>X<|...^,operators>X<|…,operators>X<|…^,operators>X<|lazy li
2411
2411
multi sub infix:<...>(**@) is assoc<list>
2412
2412
multi sub infix:<...^>(**@) is assoc<list>
2413
2413
2414
- The X < sequence operator > , which can be written either C < ... > or as C < … > (with variants C < ...^ > and C < …^ > ) will produce generic sequences on demand.
2414
+ The X < sequence operator > , which can be written either as C < ... > or as
2415
+ C < … > (with variants C < ...^ > and C < …^ > ) will produce (possibly lazy)
2416
+ generic sequences on demand.
2415
2417
2416
- The left-hand side will always include initial elements; it may
2418
+ The left-hand side will always include the initial elements; it may
2417
2419
include a generator too. The right-hand side will have an endpoint,
2418
- which can be C < Inf > or C < * > for "infinite" lists (whose elements are
2419
- only produced on demand), an expression which will end the sequence
2420
- when C < True > , or other elements such as L < Junctions|/type/Junctions > .
2420
+ which can be C < Inf > or C < * > for "infinite" lists (that is, I < lazy > lists
2421
+ whose elements are only produced on demand), an expression which will
2422
+ end the sequence when C < True > , or other elements such as
2423
+ L < Junctions|/type/Junctions > .
2421
2424
2422
2425
The sequence operator invokes the generator with as many arguments as
2423
2426
necessary. The arguments are taken from the initial elements and the
2424
- already generated elements. The default generator is C < *. > L < succ|/type/succ > or
2425
- C < *. > L < pred|/type/pred > , depending on how the end points compare:
2427
+ already generated elements. The default generator is
2428
+ C < *. > L < succ|/type/succ > or C < *. > L < pred|/type/pred > , depending on how the
2429
+ end points compare:
2426
2430
2427
2431
say 1 ... 4; # OUTPUT: «(1 2 3 4)»
2428
2432
say 4 ... 1; # OUTPUT: «(4 3 2 1)»
2429
2433
say 'a' ... 'e'; # OUTPUT: «(a b c d e)»
2430
2434
say 'e' ... 'a'; # OUTPUT: «(e d c b a)»
2431
2435
2432
- An endpoint of C < * > (L < Whatever|/type/Whatever > ), C < Inf > or C < ∞ > generates on demand an infinite sequence,
2433
- with a default generator of *.succ
2436
+ An endpoint of C < * > (L < Whatever|/type/Whatever > ), C < Inf > or C < ∞ >
2437
+ generates on demand an infinite sequence, with a default generator of
2438
+ C < *.succ >
2434
2439
2435
2440
say (1 ... *)[^5]; # OUTPUT: «(1 2 3 4 5)»
2436
2441
2437
- Custom generators need to be the last element of the list before the '...' operator.
2438
- This one takes two arguments, and generates the Fibonacci numbers
2442
+ Custom generators need to be the last element of the list before the
2443
+ '...' operator. This one takes two arguments, and generates the
2444
+ eight first Fibonacci numbers
2439
2445
2440
- say (1, 1, -> $a, $b { $a + $b } ... *)[^8]; # OUTPUT: «(1 1 2 3 5 8 13 21)»
2441
- # same but shorter
2442
- say (1, 1, * + * ... *)[^8]; # OUTPUT: «(1 1 2 3 5 8 13 21)»
2446
+ = for code
2447
+ say (1, 1, -> $a, $b { $a + $b } ... *)[^8]; # OUTPUT: «(1 1 2 3 5 8 13 21)»
2448
+ # same but shorter
2449
+ say (1, 1, * + * ... *)[^8]; # OUTPUT: «(1 1 2 3 5 8 13 21)»
2443
2450
2444
2451
Of course the generator can also take only one argument.
2445
2452
2446
- say 5, { $_ * 2 } ... 40; # OUTPUT: «5 10 20 40»
2453
+ say 5, { $_ * 2 } ... 40; # OUTPUT: «5 10 20 40»
2447
2454
2448
- There must be at least as many initial elements as arguments to the generator.
2455
+ There must be at least as many initial elements as arguments to the
2456
+ generator.
2449
2457
2450
2458
Without a generator and with more than one initial element and all initial
2451
2459
elements numeric, the sequence operator tries to deduce the generator. It
@@ -2463,7 +2471,7 @@ This allows you to write
2463
2471
2464
2472
say 1, 1, * + * ...^ *>= 100;
2465
2473
2466
- To generate all Fibonacci numbers up to but excluding 100.
2474
+ to generate all Fibonacci numbers up to but excluding 100.
2467
2475
2468
2476
The C < ... > operators consider the initial values as "generated elements" as
2469
2477
well, so they are also checked against the endpoint:
@@ -2475,18 +2483,20 @@ well, so they are also checked against the endpoint:
2475
2483
= head1 List prefix precedence
2476
2484
2477
2485
X < |list = >
2486
+ X < List assignment operator > .
2478
2487
= head2 infix C « = »
2479
2488
2480
- X < List assignment operator > . Its exact semantics are left to the container type
2481
- on the left-hand side. See L < Array|/type/Array > and L < Hash|/type/Hash > for common cases.
2489
+ In this context, it acts as the list assignment operator. Its exact
2490
+ semantics are left to the container type on the left-hand side. See
2491
+ L < Array|/type/Array > and L < Hash|/type/Hash > for common cases.
2482
2492
2483
- The distinction between item assignment and list assignment is determined by
2484
- the parser depending on the syntax of the left-hand side.
2493
+ The distinction between item assignment and list assignment is
2494
+ determined by the parser depending on the syntax of the left-hand side.
2485
2495
2486
2496
= head2 infix C « := »
2487
2497
2488
- X < Binding operator > . Whereas C < $x = $y > puts the value in C < $y > into C < $x > , C < $x :=
2489
- $y > makes C < $x > and C < $y > the same thing.
2498
+ X < Binding operator > . Whereas C < $x = $y > puts the value in C < $y > into
2499
+ C < $x > , C < $x := $y> makes C < $x > and C < $y > the same thing.
2490
2500
2491
2501
my $a = 42;
2492
2502
my $b = $a;
@@ -2505,10 +2515,11 @@ different.
2505
2515
This will output 43, since C < $b > and C < $a > both represented the same
2506
2516
object.
2507
2517
2508
- If type constrains on variables or containers are present a type check will be
2509
- performed at runtime. On failure C < X::TypeCheck::BindingType > will be thrown.
2518
+ If type constrains on variables or containers are present a type check
2519
+ will be performed at runtime. On failure C < X::TypeCheck::BindingType >
2520
+ will be thrown.
2510
2521
2511
- Please note that C < := > is a compile time construct . As such it can not
2522
+ Please note that C < := > is a compile time operator . As such it can not
2512
2523
be referred to at runtime and thus can't be used as an argument to
2513
2524
metaoperators.
2514
2525
@@ -2517,40 +2528,37 @@ metaoperators.
2517
2528
X < Read-only binding operator > , not yet implemented in Rakudo.
2518
2529
See L < C < infix := > |:=> .
2519
2530
2531
+ X < |stub operator >
2520
2532
= head2 listop C « ... »
2521
2533
2522
- X < |stub operator >
2523
- The I < yada, yada, yada > operator or I < stub > operator. If it's the only
2524
- statement in a routine or type, it marks that routine or type as a stub
2525
- (which is significant in the context of pre-declaring types and composing
2526
- roles).
2534
+ Called the I < yada, yada, yada > operator or I < stub > operator, if it's the
2535
+ only statement in a routine or type, it marks that routine or type as a
2536
+ stub (which is significant in the context of pre-declaring types and
2537
+ composing roles).
2527
2538
2528
- If the C < ... > statement is executed, it calls L < fail|/routine/fail > , with the default
2529
- message C < stub code executed> .
2539
+ If the C < ... > statement is executed, it calls L < fail|/routine/fail > ,
2540
+ with the default message C < Stub code executed> .
2530
2541
2542
+ X < Fatal stub operator > .
2531
2543
= head2 listop C « !!! »
2532
2544
2533
- X < Fatal stub operator > .
2545
+ If it's the only statement in a routine or type, it marks that routine
2546
+ or type as a stub (which is significant in the context of pre-declaring
2547
+ types and composing roles).
2534
2548
2535
- If it's the only
2536
- statement in a routine or type, it marks that routine or type as a stub
2537
- (which is significant in the context of pre-declaring types and composing
2538
- roles).
2549
+ If the C < !!! > statement is executed, it calls L < die|/routine/die > , with
2550
+ the default message C < Stub code executed > .
2539
2551
2540
- If the C < !!! > statement is executed, it calls L < die|/routine/die > , with the default
2541
- message C < stub code executed > .
2542
-
2543
- = head2 listop C « ??? »
2544
2552
2545
2553
X < Admonitory stub operator > .
2554
+ = head2 listop C « ??? »
2546
2555
2547
- If it's the only
2548
- statement in a routine or type, it marks that routine or type as a stub
2549
- (which is significant in the context of pre-declaring types and composing
2550
- roles).
2556
+ If it's the only statement in a routine or type, it marks that routine
2557
+ or type as a stub (which is significant in the context of pre-declaring
2558
+ types and composing roles).
2551
2559
2552
- If the C < ??? > statement is executed, it calls L < warn|/routine/warn > , with the default
2553
- message C < stub code executed> .
2560
+ If the C < ??? > statement is executed, it calls L < warn|/routine/warn > ,
2561
+ with the default message C < Stub code executed> .
2554
2562
2555
2563
= head2 Reduction operators
2556
2564
@@ -2562,7 +2570,8 @@ that reduces using that operation.
2562
2570
my @a = (5, 6);
2563
2571
say [*] @a; # 5 * 6 = 30
2564
2572
2565
- Reduction operators have the same associativity as the operators they are based on.
2573
+ Reduction operators have the same associativity as the operators they
2574
+ are based on.
2566
2575
2567
2576
say [-] 4, 3, 2; # 4-3-2 = (4-3)-2 = -1
2568
2577
say [**] 4, 3, 2; # 4**3**2 = 4**(3**2) = 262144
@@ -2574,19 +2583,20 @@ Reduction operators have the same associativity as the operators they are based
2574
2583
Same as L < infix &&|/language/operators#infix_%26%26 > , except with looser
2575
2584
precedence.
2576
2585
2577
- Short-circuits so that it returns the first operand that evaluates to C < False > , otherwise
2578
- returns the last operand. Note that C < and > is easy
2586
+ Short-circuits so that it returns the first operand that evaluates to
2587
+ C < False > , otherwise returns the last operand. Note that C < and > is easy
2579
2588
to misuse. See L < traps|/language/traps#Loose_boolean_operators > .
2580
2589
2581
2590
= head2 infix C « andthen » X < |andthen >
2582
2591
2583
- The C < andthen > operator returns L « C < Empty > |/type/Slip#index-entry-Empty-Empty» upon encountering
2584
- the first L < undefined|/routine/defined > argument, otherwise the last argument.
2585
- Last argument
2586
- is returned as-is, without being checked for definedness at all.
2587
- Short-circuits. The result of the left side is bound to C < $_ > for the
2588
- right side, or passed as arguments if the right side is a
2589
- L « C < Callable > |/type/Callable» , whose L < count|/type/count > must be C < 0 > or C < 1 > .
2592
+ The C < andthen > operator returns
2593
+ L « C < Empty > |/type/Slip#index-entry-Empty-Empty» upon encountering the
2594
+ first L < undefined|/routine/defined > argument, otherwise the last
2595
+ argument. Last argument is returned as-is, without being checked for
2596
+ definedness at all. Short-circuits. The result of the left side is bound
2597
+ to C < $_ > for the right side, or passed as arguments if the right side is
2598
+ a L « C < Callable > |/type/Callable» , whose L < count|/type/count > must be C < 0 >
2599
+ or C < 1 > .
2590
2600
2591
2601
A handy use of this operator is to alias a routine's return value to C < $_ > and
2592
2602
to do additional manipulation with it, such as printing or returning it to
0 commit comments