@@ -69,7 +69,7 @@ how identifiers are defined.
69
69
= head2 Identifiers
70
70
71
71
Raku allows the use of dashes (C < - > ), underscores (C < _ > ),
72
- apostrophes (C < ' > ), and alphanumerics in identifiers, :
72
+ apostrophes (C < ' > ), and alphanumerics in identifiers:
73
73
74
74
sub test-doesn't-hang { ... }
75
75
my $ความสงบ = 42;
@@ -223,8 +223,8 @@ name.
223
223
The C < $ > sigil is now always used with "scalar" variables (e.g. C < $name > ),
224
224
and no longer for L < array indexing|#[]_Array_indexing/slicing > and L < Hash
225
225
indexing|#{}_Hash_indexing/slicing > . That is, you can still use C < $x[1] >
226
- and C < $x{"foo"} > , but it will act on $x , with no effect on a similarly
227
- named @x or %x . Those would now be accessed with @x[1] and %x{"foo"}.
226
+ and C < $x{"foo"} > , but it will act on C < $x > , with no effect on a similarly
227
+ named C < @x > or C < %x > . Those would now be accessed with C < @x[1] > and C < %x{"foo"} > .
228
228
229
229
= head3 C < @ > Array
230
230
@@ -465,8 +465,8 @@ my @array = 4,8,15;
465
465
say @array; # OUTPUT: «[66 8 15]»
466
466
= end code
467
467
468
- The underlying Array object of C < @array > is passed, and its first value modified
469
- inside the declared routine.
468
+ The underlying C < Array > object of C < @array > is passed, and its first value
469
+ modified inside the declared routine.
470
470
471
471
In Perl 5, the syntax for dereferencing an entire reference is the type-sigil
472
472
and curly braces, with the reference inside the curly braces. In Raku, this
@@ -546,7 +546,7 @@ my @all_numbers = |@numbers, 400, |@more_numbers;
546
546
That way one can concatenate arrays.
547
547
548
548
Note that one does not need to have any parentheses on the right-hand side:
549
- the List Separator takes care of creating the list, B < not > the parentheses!
549
+ the list separator takes care of creating the list, B < not > the parentheses!
550
550
551
551
= head2 C « <=> cmp » Three-way comparisons
552
552
@@ -677,13 +677,13 @@ $food = 'grape' ~ 'fruit'; # Raku
677
677
678
678
= head2 C < x > List repetition or string repetition operator
679
679
680
- In Perl 5, C < x > is the Repetition operator, which behaves differently in
680
+ In Perl 5, C < x > is the repetition operator, which behaves differently in
681
681
scalar or list contexts:
682
682
= item in scalar context C < x > repeats a string;
683
683
= item in list context C < x > repeats a list, but only if the left argument
684
684
is parenthesized!
685
685
686
- Raku uses two different Repetition operators to achieve the above:
686
+ Raku uses two different repetition operators to achieve the above:
687
687
= item C < x > for string repetitions (in any context);
688
688
= item C < xx > for list repetitions (in any context).
689
689
@@ -745,7 +745,7 @@ it does not allow for an C<elsif> or C<else> clause.
745
745
= head3 C < given > -C < when >
746
746
747
747
The C < given > -C < when > construct is like a chain of C < if > -C < elsif > -C < else >
748
- statements or like the C < switch > -C < case > construct in e.g. C . It has the
748
+ statements or like the C < switch > -C < case > construct C, for example . It has the
749
749
general structure:
750
750
751
751
= for code :lang<pseudo>
@@ -880,8 +880,8 @@ for (@cars) {...} # Perl 5; $_ is read-write
880
880
for @cars {...} # Raku; $_ is read-write
881
881
for @cars <-> $_ {...} # Raku; $_ is also read-write
882
882
883
- It is possible to consume more than one element of the list in each iteration simply specifying
884
- more than one variable after the arrow operator:
883
+ It is possible to consume more than one element of the list in each iteration
884
+ simply specifying more than one variable after the arrow operator:
885
885
886
886
= begin code
887
887
my @array = 1..10;
@@ -890,6 +890,17 @@ for @array -> $first, $second {
890
890
}
891
891
= end code
892
892
893
+ For cases in which the number of elements iterated over isn't a multiple
894
+ of the number of variables after the arrow operator, you can provide variables
895
+ with default values:
896
+
897
+ = begin code
898
+ my @array = 1..9;
899
+ for @array -> $first, $second = 0 {
900
+ say "First is $first, second is $second";
901
+ }
902
+ = end code
903
+
893
904
= head4 C < each >
894
905
895
906
Here is the equivalent to Perl 5’s C < while…each(%hash) > or C < while…each(@array) >
0 commit comments