Course of Raku / Advanced / Modules / Packages and namespaces 🆕 / Exercises / A nested name
Solution: A nested name
Here is a possible solution to the task.
Code
module Outer {
module Inner {
our $base = 10;
our sub doubled { $base * 2 }
}
}
say $Outer::Inner::base;
say Outer::Inner::doubled();🦋 You can find the source code in the file nested-name.raku.
Output
10
20Comments
Nesting one namespace inside another builds a longer
::path. Both the variable and the subroutine live two levels deep, inOuter::Inner.The full name
$Outer::Inner::basereaches the variable, andOuter::Inner::doubled()reaches the subroutine through the same two levels. A sub name carries no sigil, so unlike the variable it has no$in front.Both members are declared with
our, which is what makes them visible outside their module. Amydeclaration would have kept them private toInner.