Course of Raku / Advanced / Subroutines / Anonymous subroutines

Quiz — Pointy blocks

What does the following program print?

(-> $a, $b { $a * $b })(3, 4).say
112
07
034
0an error

A pointy block can list several parameters: -> $a, $b takes two. Here it is not stored in a variable at all — it is wrapped in parentheses and called straight away with (3, 4), binding $a to 3 and $b to 4. The block multiplies them to give 12, and the postfix .say prints it.

Course navigation

Solution: Sum with the & sigil   |   Modules