Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Sync some comments with reality, provide a non-slippy example
  • Loading branch information
skids committed Dec 25, 2015
1 parent 47091a7 commit 81f6147
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions doc/Language/control.pod
Expand Up @@ -144,15 +144,16 @@ The statement modifier form is probably best used sparingly.
The C<if> statement itself will either L<slip|/type/Slip> us an empty list, if
it does not run the block, or it will return the value which the block produces:
my $c = 0; say (1, (if 1 { $c += 42; 2; }), 3, $c); # says "1 2 3 42"
my $d = 0; say (1, (if 0 { $d += 42; 2; }), 3, $d); # says "1 3 0"
my $d = 0; say (1, (if 0 { $d += 42; 2; }), 3, $d); # says "(1 3 0)"
my $c = 0; say (1, (if 1 { $c += 42; 2; }), 3, $c); # says "(1 2 3 42)"
say (1, (if 1 { 2, 2 }), 3); # does not slip, says "(1 (2 2) 3)"
For the statement modifier it is the same, except you have the value
of the statement instead of a block:
say (1, (42 if True) , 2); # says "1 42 2"
say (1, (42 if False), 2); # says "1 2"
say (1, 42 if False , 2); # says "1 42" because "if False, 2" is true
say (1, (42 if True) , 2); # says "(1 42 2)"
say (1, (42 if False), 2); # says "(1 2)"
say (1, 42 if False , 2); # says "(1 42)" because "if False, 2" is true
The C<if> does not change the topic (C<$_>) by default. In order to access
the value which the conditional expression produced, you have to ask
Expand Down Expand Up @@ -215,15 +216,15 @@ All the same rules for semicolons and newlines apply, consistently
elsif False { say "NO" }
else { say "yes" } ; # -> says "yes"
The whole thing produces either an empty list (if no blocks were run)
or the value produced by the block that did run:
The whole thing either L<slips|/type/Slip> us an empty list (if no blocks
were run) or returns the value produced by the block that did run:
my $c = 0; say (1,
(if 0 { $c += 42; "two"; } else { $c += 43; 2; }),
3, $c); # says "1 2 3 43"
my $d = 0; say (1,
(if 0 { $d += 42; "two"; } elsif False { $d += 43; 2; }),
3, $d); # says "1 3 0"
3, $d); # says "(1 3 0)"
my $c = 0; say (1,
(if 0 { $c += 42; "two"; } else { $c += 43; 2; }),
3, $c); # says "(1 2 3 43)"
It's possible to obtain the value of the previous expression inside an
C<else>, which could be from C<if> or the last C<elsif> if any are
Expand Down

0 comments on commit 81f6147

Please sign in to comment.