In Raku, how can I list:
To list lexical variables in scope, I use say ::;
and Pseudo packages.
You can't, generally.
I guess technically you could devise a pad walker routine that would check all of the pads to see if there was a dynamic variable defined in a pad and create a list of it. But some dynamic variables don't actually exist until they're actually used, e.g. $*DISTRO
(which lives in the PROCESS::
namespace if it was referenced):
say PROCESS::<$DISTRO>:exists; # False
$*DISTRO; # just need to refer to it
say PROCESS::<$DISTRO>:exists; # True
Compile time variables generally only exist at compile time and are generally codegenned as a constant. A prime example of that is $?LINE
, which has a value dependent on the line in your code.
Packages can be lexically (my
) scoped, or OUR::
scoped. And as such, they can be found. The big problem with descending into subclasses is that Rakudo is an irresponsible parent. A package knows of its parent classes, but not the other way around.
The PseudoStash
class contains an internal data structure that contains the names of all the possible pseudo packages, but that is not externally available. I guess it could be made that way.
Perhaps a more directed question about why you would want the information, would give a better, more useful answer?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With