Course of Raku / Advanced / Containers / Introspecting containers / Exercises / Describe a variable

Solution: Describe a variable

Here is a possible solution to the task.

Code

my Str $lang = 'Raku';

say $lang.^name;
say $lang.VAR.^name;
say $lang.VAR.name;

🦋 You can find the source code in the file describe-a-variable.raku.

Output

Str
Scalar
$lang

Comments

  1. .^name returns the type of the value stored in the container, which is Str.

  2. .VAR returns the underlying container, and .^name on it returns Scalar — the type of the container itself.

  3. .VAR.name returns the name of the variable, $lang, including its sigil. Note that this is the name method, not the ^name meta-method used on the first two lines.

Course navigation

Describe a variable   |   What is it