Course of Raku / Advanced / Containers / Contexts 🆕 / Exercises / Force a number

Solution: Force a number

Here is a possible solution to the task.

Code

my @a = 1, 2, 3;
say +@a;

🦋 You can find the source code in the file force-a-number.raku.

Output

3

Comments

  1. The + prefix forces numeric context.

  2. In numeric context, an array becomes its element count, so the result is 3.

Course navigation

Force a number   |   A Boolean check