Skip to content

Commit 33b41a6

Browse files
committed
Merge pull request #243 from gfldex/master
document implicit binding of state variables
2 parents 4a4055e + 72fadc1 commit 33b41a6

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

doc/Language/variables.pod

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,17 @@ As with C<my>, declaring multiple C<state> variables must be placed
556556
in parentheses and for declaring a single variable, parentheses may
557557
be omitted.
558558
559+
Please note that many operators come with implicit binding, what will lead to actions at a distance. Use C<.clone> or coercion to create a new container that can be bound to.
560+
561+
my @a;
562+
sub f () {
563+
state $i;
564+
$i++;
565+
@a.push: "k$i" => $i # <-- .clone goes here
566+
};
567+
f for 1..3;
568+
dd @a; # «Array $var = $[:k1(3), :k2(3), :k3(3)]»
569+
559570
=head3 The C<$> Variable
560571
561572
As well as explicitly declared named state variables C<$> can be used

0 commit comments

Comments
 (0)