Course of Raku / Advanced / Modules / Module introspection / Exercises

Look up a symbol

Problem

Besides listing a package’s names, you can reach a name dynamically by using it as a key in the package’s stash. You are given a module Circle.rakumod:

unit module Circle;

our $pi = 3.14;

Write a separate program that loads the module and prints the value of $pi by looking it up in the stash with Circle::{'$pi'} — not with the qualified $Circle::pi.

Example

Run with the module on the search path, the program prints:

$ raku -I. lookup.raku
3.14

Solution

See the solution

Course navigation

Solution: List the symbols   |   Solution: Look up a symbol