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
Circle::is the package of the module, and.keyslists the names it contains, each including its sigil..elemscounts those names — the module defines twoourvariables, so the count is2..keysdoes not guarantee any particular order, so we apply.sortto get a stable, alphabetical result($pi $tau). Without sorting, the two names could come out in either order between runs.