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
0Comments
The
is default(0)trait gives the container a default value. Because nothing has been assigned, reading$countreturns that default, so the first line prints0..VAR.defaultasks the container itself for its declared default, which is also0. Without the trait, an untyped container would have defaulted to(Any).