Course of Raku / Advanced /
Subroutines / Anonymous subroutines / Exercises / Sum with
the & sigil
Solution: Sum with the
& sigil
Here is a possible solution to the task.
Code
my &add = -> $a, $b {
$a + $b;
};
say add(2, 3);🦋 You can find the source code in the file sum-with-sigil.raku.
Output
5Comments
The pointy block lists two parameters,
-> $a, $b, so the anonymous subroutine takes two arguments.Because the variable is declared with the
&sigil, it can be called asadd(2, 3)exactly like a named subroutine — no sigil at the call site — giving5.