Skip to content

Commit 159f1ef

Browse files
authored
a little more word-smithing
attempt at clarity--please change or comment
1 parent 11c89a0 commit 159f1ef

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

doc/Language/control.pod6

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ There are also C<with> and C<without> statement modifiers:
306306
=head1 X<when|control flow>
307307
308308
The C<when> block is similar to an C<if> block and either or both can be used
309-
in an outer block, they also both have a statement modifier form.
309+
in an outer block, they also both have a "statement modifier form."
310310
But there is a difference in how following code in the same, outer
311311
block is handled: When the C<when> block is executed, control is passed to
312312
the enclosing block and following statements are ignored; but when the C<if>
@@ -332,9 +332,22 @@ Should the C<if> and C<when> blocks above appear at file scope, following
332332
statements would be executed in each case.
333333
334334
There is one other feature a C<when> has that C<if> doesn't: the C<when>'s boolean
335-
test defaults to C<$_ ~~> while the C<if>'s does not.
335+
context test defaults to C<$_ ~~> while the C<if>'s does not. That has an effect on
336+
how one uses the X in the C<when> block without a value for <$_> (it's 'Any' in
337+
that case and Any smart matches on True: Any ~~ True => True). Consider the following:
336338
337-
C<when> also has a statement modifier form which does not effect execution
339+
=begin code :skip-test
340+
{
341+
my $a = 1;
342+
my $b = True;
343+
when $a { say 'a' }; # no output
344+
when so $a { say 'a' } # a (in "so $a" 'so' coerces $a to Boolean context True
345+
# which matches with Any)
346+
when $b { say 'b' }; # b (b is True as defined so matches with Any)
347+
}
348+
=end code
349+
350+
Finally, C<when>'s statement modifier form does not effect execution
338351
of following statements either inside or outside of another block:
339352
340353
=begin code :skip-test

0 commit comments

Comments
 (0)