Documentation for prefix let
assembled from the following pages:
Language documentation: Operators §
From Operators
(Operators) prefix let §
sub prefix:<let>(Mu is rw)
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 = "Jane Doe"; say "We got $name";
This code provides a default name for $name
. If the user exits from the prompt or simply does not provide a valid input for $name
; let
will restore the default value provided at the top. If user input is valid, it will keep that.
Language documentation: Variables §
From Variables
(Variables) prefix let §
Restores the previous value if the block exits unsuccessfully. A successful exit means the block returned a defined value or a list.
my = 42; say ;
In the above case, if the Bool.pick
returns true, the answer will stay as 84 because the block returns a defined value (say
returns True
). Otherwise the die
statement will cause the block to exit unsuccessfully, resetting the answer to 42.