Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Changed code example for C<state> and tweaked related language
  • Loading branch information
dha committed Sep 16, 2015
1 parent 5d3eae7 commit 9be03d2
Showing 1 changed file with 17 additions and 25 deletions.
42 changes: 17 additions & 25 deletions lib/Language/variables.pod
Expand Up @@ -512,42 +512,34 @@ Therefore, the subroutine
=begin code
sub a {
state @x = 1, 1;
@x.push(1, 1)
}
=end code
state @x;
@x.push(++$)
};
will continue to append each time it is called. So,
=begin code
say a;
say "next";
say a;
say "next";
say a;
say a for 1..6;
=end code
will output
will continue to append each time it is called. So it will output
=begin code
[1 1 1 1]
next
[1 1 1 1 1 1]
next
[1 1 1 1 1 1 1 1]
[1]
[1 2]
[1 2 3]
[1 2 3 4]
[1 2 3 4 5]
[1 2 3 4 5 6]
=end code
Also, just like C<my>, declaring multiple C<state> variables must be placed in
parentheses and for declaring a single variable, parentheses may be
omitted.
As seen in this example, C<$> can be used as an anonymous state variable
without an explicit C<state> declaration.
C<$> can be used as an anonymous state variable without an explicit
C<state> declaration.
As with C<my>, declaring multiple C<state> variables must be placed
in parentheses and for declaring a single variable, parentheses may
be omitted.
=begin code
Expand Down

0 comments on commit 9be03d2

Please sign in to comment.