Course of Raku / Advanced / Subroutines / Anonymous subroutines / Exercises

Sum with the & sigil

Problem

A pointy block can take more than one parameter, and the & sigil lets you call the result by name. Store a two-parameter pointy block that adds its arguments in a variable &add declared with the & sigil. Then call it as add(2, 3) — without the sigil — and print the result.

Example

The program prints:

5

Solution

See the solution

Course navigation

Solution: An anonymous square   |   Solution: Sum with the & sigil