Course of Raku / Advanced / Modules / Module introspection / Exercises / Look up a symbol
Solution: Look up a symbol
Here is a possible solution to the task.
Code
The program, lookup.raku:
use Circle;
say Circle::{'$pi'};🦋 You can find both source files in the exercises/advanced/module-introspection/lookup-symbol directory.
Output
$ raku -I. lookup.raku
3.14Comments
Circle::is the module’s stash, and using a name as a key —Circle::{'$pi'}— fetches the value stored under it. The key must include the sigil, just as the listed names do.This reaches the same value as the qualified
$Circle::pi, but because the name is an ordinary string it can be computed at run time rather than written out in the source.