Course of Raku / Advanced / Modules / Module introspection / Exercises / List the symbols

Solution: List the symbols

Here is a possible solution to the task.

Code

The program, list.raku:

use Circle;

say Circle::.keys.elems;
say Circle::.keys.sort;

🦋 You can find both source files in the exercises/advanced/module-introspection/list-the-symbols directory.

Output

$ raku -I. list.raku
2
($pi $tau)

Comments

  1. Circle:: is the package of the module, and .keys lists the names it contains, each including its sigil.

  2. .elems counts those names — the module defines two our variables, so the count is 2.

  3. .keys does not guarantee any particular order, so we apply .sort to get a stable, alphabetical result ($pi $tau). Without sorting, the two names could come out in either order between runs.

Course navigation

List the symbols   |   Look up a symbol