Skip to content

Commit

Permalink
let example (duplicated)
Browse files Browse the repository at this point in the history
  • Loading branch information
LLFourn committed Nov 3, 2015
1 parent c16e4d8 commit 89362d6
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
25 changes: 23 additions & 2 deletions doc/Language/operators.pod
Expand Up @@ -703,8 +703,29 @@ except that C<temp> does not reset the value).
sub prefix:<let>(Mu $a is rw)
Hypothetical reset: if the current scope is exited either through an exception
or C<fail()>, the old value is restored.
Like the L<C<temp>|#prefix_tmp> prefix, but only restores the
value if the block exits unsuccessfully. A successful exit means the
block returned a defined value or a list.
my $answer = 42;
{
let $answer = 84;
die if Bool.pick;
CATCH {
default { say "it's been reset :(" }
}
say "we made it 84 sticks!";
}
say $answer;
In the above case, if the C<Bool.pick> returns true, the answer will
stay as 84 because the block returns a defined value (C<say> returns
true). Otherwise the C<die> statement will cause the block to exit
unsuccessfully, resetting the answer to 42.
=comment this is duplicated in variables.pod
=head1 Nonchaining Binary Precedence
Expand Down
25 changes: 23 additions & 2 deletions doc/Language/variables.pod
Expand Up @@ -647,8 +647,29 @@ say $cookies; # -> 6
=head2 The C<let> Prefix
Like the L<C<temp>|#The_temp_Listop> listop, but only restores the value if
the block exits unsuccessfully.
Like the L<C<temp>|#The_temp_Prefix> prefix, but only restores the
value if the block exits unsuccessfully. A successful exit means the
block returned a defined value or a list.
my $answer = 42;
{
let $answer = 84;
die if Bool.pick;
CATCH {
default { say "it's been reset :(" }
}
say "we made it 84 sticks!";
}
say $answer;
In the above case, if the C<Bool.pick> returns true, the answer will
stay as 84 because the block returns a defined value (C<say> returns
true). Otherwise the C<die> statement will cause the block to exit
unsuccessfully, resetting the answer to 42.
=comment this is duplicated in operators.pod
=head1 Type Constraints and Initialization
Expand Down

0 comments on commit 89362d6

Please sign in to comment.