Course of Raku / Advanced / Containers / Introspecting containers / Exercises

The container’s default

Problem

A container can carry a default value, set with the is default trait. Until you assign anything, reading the variable gives back that default, and .VAR.default reports it.

Declare a scalar $count with a default of 0. Without assigning anything to it, print the variable itself, and then print its container’s default. Both lines should show 0.

Example

The program prints:

0
0

Solution

See the solution

Course navigation

Solution: What is it   |   Solution: The container’s default