Course of Raku / Advanced / Containers / Introspecting containers / Exercises / The container’s default

Solution: The container’s default

Here is a possible solution to the task.

Code

my $count is default(0);

say $count;
say $count.VAR.default;

🦋 You can find the source code in the file container-default.raku.

Output

0
0

Comments

  1. The is default(0) trait gives the container a default value. Because nothing has been assigned, reading $count returns that default, so the first line prints 0.

  2. .VAR.default asks the container itself for its declared default, which is also 0. Without the trait, an untyped container would have defaulted to (Any).

Course navigation

The container’s default   |   More about built-in types