Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Rewrites example and text to avoid repetition
This fixes #2237, but also refers to #1924. It's always better to have
two valid examples, than to have a single one.

Another alternative is, of course, to eliminate indexing of one of
them, but this is probably better.
  • Loading branch information
JJ committed Aug 8, 2018
1 parent 35c5c94 commit cd318ff
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions doc/Language/operators.pod6
Expand Up @@ -1388,26 +1388,28 @@ the C<temp> was undone, you'd get the original value, not the C<temp> one:
sub prefix:<let>(Mu $a is rw)
Restores the previous value if the block exits unsuccessfully. A
successful exit means the block returned a defined value or a list.
Refers to a variable in an outer scope whose value will be restored if the block
exits unsuccessfully, implying that the block returned a defined object.
my $answer = 42;
=begin code
my $name = "Jane Doe";
{
let $answer = 84;
die if not Bool.pick;
CATCH {
default { say "it's been reset :(" }
}
say "we made it 84 sticks!";
{
let $name = prompt("Say your name ");
die if !$name;
CATCH {
default { say "No name entered" }
}
say "We have $name";
}
say $answer;
say "We got $name";
=end code
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.
This code provides a default name for C<$name>. If the user exits from the
prompt of simply does not provide a valid input for C<$name>; C<let> will
restore the default value provided at the top. If user input is valid, it will
keep that.
=comment this is duplicated in variables.pod
Expand Down

0 comments on commit cd318ff

Please sign in to comment.