Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
document implicit binding of state variables
  • Loading branch information
gfldex committed Dec 14, 2015
1 parent 4a4055e commit 72fadc1
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions doc/Language/variables.pod
Expand Up @@ -556,6 +556,17 @@ As with C<my>, declaring multiple C<state> variables must be placed
in parentheses and for declaring a single variable, parentheses may
be omitted.
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.
my @a;
sub f () {
state $i;
$i++;
@a.push: "k$i" => $i # <-- .clone goes here
};
f for 1..3;
dd @a; # «Array $var = $[:k1(3), :k2(3), :k3(3)]»
=head3 The C<$> Variable
As well as explicitly declared named state variables C<$> can be used
Expand Down

0 comments on commit 72fadc1

Please sign in to comment.