Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to list dynamic and Compile-time variables in Raku [closed]

In Raku, how can I list:

  1. Dynamic variables
  2. Compile time variables
  3. Packages
  4. Pseudo packages

To list lexical variables in scope, I use say ::; and Pseudo packages.

like image 285
Tinmarino Avatar asked Apr 06 '20 01:04

Tinmarino


Video Answer


1 Answers

You can't, generally.

Dynamic variables

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

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

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.

Pseudo packages

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.

Conclusion

Perhaps a more directed question about why you would want the information, would give a better, more useful answer?

like image 198
Elizabeth Mattijsen Avatar answered Sep 19 '22 12:09

Elizabeth Mattijsen