Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to create new lexical symbols in other contexts at runtime?

I'm writing a module for creating enums with custom behaviour. What I do at the moment is add the enum to the GLOBAL package, but that doesn't install any lexical symbols unless you create the enum in one module and import it from another. Using BEGIN $*W.install_lexical_symbol(...) is not an option since the values for the enum could be obtained from, say, a network connection, and would block compilation until the values are received. Is it possible to install the lexical symbol in the caller's context at runtime? If so, how?

like image 277
Kaiepi Avatar asked Mar 18 '19 19:03

Kaiepi


1 Answers

I'm going to say flat out "No".

(I usually learn to regret doing that with P6 but what the hey.)

My primary evidence is comments like "the set of symbols in a lexical scope is immutable after compile time".

Maybe grab a sick bag and go read the suggestions at How to define variable names dynamically in Perl 6? that are both evil and still not evil enough to do what I think you're asking for.

When you've finished throwing up, please seal the bag and then visit the freenode IRC channel #perl6-dev where the true experts in things related to guts hang out. (I think you know about that but thought I'd include it in this answer for posterity and because I seem to have a sick sense of humor.)

like image 170
raiph Avatar answered Nov 15 '22 09:11

raiph