Skip to content

Commit

Permalink
Some minor reflow
Browse files Browse the repository at this point in the history
  • Loading branch information
JJ committed Jul 7, 2018
1 parent 43d7e98 commit ea97a98
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions doc/Language/traps.pod6
Expand Up @@ -93,10 +93,11 @@ is called, but the counter is not increasing:
# Count is 0
=end code
When it comes to state variables, the block in which the vars are declared gets
cloned—and vars get initialized anew—whenever that block's block is re-entered.
This lets constructs like the one below behave appropriately: the state variable
inside the loop gets initialized anew each time the sub is called:
When it comes to state variables, the block in which the vars are
declared gets cloned — and vars get initialized anew—whenever that
block's block is re-entered. This lets constructs like the one below
behave appropriately: the state variable inside the loop gets
initialized anew each time the sub is called:
=begin code
sub count-it {
Expand All @@ -122,12 +123,13 @@ inside the loop gets initialized anew each time the sub is called:
# Count is 2
=end code
The same layout exists in our buggy program. The C<{ }> inside a double-quoted
string isn't merely an interpolation to execute a piece of code. It's actually
its own block, which is just as in the example above gets cloned each time the
sub is entered, re-initializing our state variable. To get the right count,
we need to get rid of that inner block, using a scalar contextualizer to
interpolate our piece of code instead:
The same layout exists in our buggy program. The C<{ }> inside a
double-quoted string isn't merely an interpolation to execute a piece of
code. It's actually its own block, which is just as in the example above
gets cloned each time the sub is entered, re-initializing our state
variable. To get the right count, we need to get rid of that inner
block, using a scalar contextualizer to interpolate our piece of code
instead:
=begin code
sub count-it { say "Count is $($++)" }
Expand Down

0 comments on commit ea97a98

Please sign in to comment.