In Functions§
See primary documentation in context for Blocks and lambdas
Whenever you see something like { $_ + 42 }
, -> $a, $b { $a ** $b }
, or { $^text.indent($:spaces) }
, that's Block
syntax; the ->
is considered also part of the block. Statements such as if
, for
, while
are followed by these kind of blocks.
for 1, 2, 3, 4 -> ,# OUTPUT: «1234»
They can also be used on their own as anonymous blocks of code.
say (3, 4) # OUTPUT: «25»
Please note that this implies that, despite the fact that statements such as if
do not define a topic variable, they actually can:
my = 33;if ** 33 -># OUTPUT: «129110040087761027839616029934664535539337183380513 is not null»
For block syntax details, see the documentation for the Block
type.