Code object with its own lexical scope
Block is a code object meant for small-scale code reuse. A block is created syntactically by a list of statements enclosed in curly braces. The literal for creating an empty block is
Without an explicit signature or placeholder arguments, a block has
$_ as a positional argument, which defaults to the outer scope's
$_. Thus it will inherit the topic if there is any.
my = ;say .^name; # OUTPUT: «Block␤»say ('hello'); # OUTPUT: «HELLO␤»say .signature; # OUTPUT: «(;; $_? is raw = OUTER::<$_>)␤»
A block can have a
<-> and the block:
my = -> , = 2 ;say (40); # OUTPUT: «42␤»
my = <-> , ;my (, ) = (2, 4);(, );say ; # OUTPUT: «4␤»
The last statement is the implicit return value of the block.
say .(); # OUTPUT: «1␤»
Bare blocks are automatically executed in the order they appear:
say 1; # OUTPUT: «1␤»say 3; # OUTPUT: «3␤»