File tree Expand file tree Collapse file tree 2 files changed +5
-4
lines changed Expand file tree Collapse file tree 2 files changed +5
-4
lines changed Original file line number Diff line number Diff line change @@ -872,12 +872,13 @@ for my $car (@cars) {...} # Perl 5; read-write
872
872
for @cars -> $car {...} # Raku; read-only
873
873
for @cars <-> $car {...} # Raku; read-write
874
874
875
- If the default topic C < $_ > is being used, it is also read-write.
875
+ In Raku and unlike Perl, the default topic C < $_ > will behave in the same way,
876
+ becoming read-only when used as a topic variable.
876
877
877
878
= for code :lang<perl5>
878
879
for (@cars) {...} # Perl 5; $_ is read-write
879
880
= for code :preamble<no strict;>
880
- for @cars {...} # Raku; $_ is read-write
881
+ for @cars {...} # Raku; $_ is read-only
881
882
for @cars <-> $_ {...} # Raku; $_ is also read-write
882
883
883
884
It is possible to consume more than one element of the list in each iteration
Original file line number Diff line number Diff line change @@ -579,8 +579,8 @@ for @foo <-> $value {
579
579
say @bar; # # OUTPUT: «[Odd Even Odd]»
580
580
= end code
581
581
582
- By default the topic variable C « $_ » is a read-write alias. Thus, if you want
583
- to use it as a read-only alias you must indicate it by using C « -> » .
582
+ This rule also applies to the topic variable C « $_ » , which by default is a
583
+ read-write alias; it will become read-only if it's used in a C « -> » loop .
584
584
585
585
my @foo = 1..3;
586
586
for @foo -> $_ { $_.say }
You can’t perform that action at this time.
0 commit comments