File tree Expand file tree Collapse file tree 2 files changed +46
-4
lines changed Expand file tree Collapse file tree 2 files changed +46
-4
lines changed Original file line number Diff line number Diff line change @@ -703,8 +703,29 @@ except that C<temp> does not reset the value).
703
703
704
704
sub prefix:<let>(Mu $a is rw)
705
705
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
708
729
709
730
= head1 Nonchaining Binary Precedence
710
731
Original file line number Diff line number Diff line change @@ -647,8 +647,29 @@ say $cookies; # -> 6
647
647
648
648
= head2 The C < let > Prefix
649
649
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
652
673
653
674
= head1 Type Constraints and Initialization
654
675
You can’t perform that action at this time.
0 commit comments