Skip to content

Commit 89362d6

Browse files
committed
let example (duplicated)
1 parent c16e4d8 commit 89362d6

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

doc/Language/operators.pod

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -703,8 +703,29 @@ except that C<temp> does not reset the value).
703703
704704
sub prefix:<let>(Mu $a is rw)
705705
706-
Hypothetical reset: if the current scope is exited either through an exception
707-
or C<fail()>, the old value is restored.
706+
Like the L<C<temp>|#prefix_tmp> prefix, but only restores the
707+
value if the block exits unsuccessfully. A successful exit means the
708+
block returned a defined value or a list.
709+
710+
my $answer = 42;
711+
712+
{
713+
let $answer = 84;
714+
die if Bool.pick;
715+
CATCH {
716+
default { say "it's been reset :(" }
717+
}
718+
say "we made it 84 sticks!";
719+
}
720+
721+
say $answer;
722+
723+
In the above case, if the C<Bool.pick> returns true, the answer will
724+
stay as 84 because the block returns a defined value (C<say> returns
725+
true). Otherwise the C<die> statement will cause the block to exit
726+
unsuccessfully, resetting the answer to 42.
727+
728+
=comment this is duplicated in variables.pod
708729
709730
=head1 Nonchaining Binary Precedence
710731

doc/Language/variables.pod

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -647,8 +647,29 @@ say $cookies; # -> 6
647647
648648
=head2 The C<let> Prefix
649649
650-
Like the L<C<temp>|#The_temp_Listop> listop, but only restores the value if
651-
the block exits unsuccessfully.
650+
Like the L<C<temp>|#The_temp_Prefix> prefix, but only restores the
651+
value if the block exits unsuccessfully. A successful exit means the
652+
block returned a defined value or a list.
653+
654+
my $answer = 42;
655+
656+
{
657+
let $answer = 84;
658+
die if Bool.pick;
659+
CATCH {
660+
default { say "it's been reset :(" }
661+
}
662+
say "we made it 84 sticks!";
663+
}
664+
665+
say $answer;
666+
667+
In the above case, if the C<Bool.pick> returns true, the answer will
668+
stay as 84 because the block returns a defined value (C<say> returns
669+
true). Otherwise the C<die> statement will cause the block to exit
670+
unsuccessfully, resetting the answer to 42.
671+
672+
=comment this is duplicated in operators.pod
652673
653674
=head1 Type Constraints and Initialization
654675

0 commit comments

Comments
 (0)