-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow access to the COMPILING:: variable scope in the macro's caller #313
Comments
It bothers me a bit that I had to invent the I believe this code preserves the simplicity of lexicals while achieving the same effect:
Some notes:
|
Note that the If we put the initialization on the I guess it's a little bit unexpected that the initializer of a |
And good riddance, too. I realized later that having that syntax would've sold the static properties of lexical variables down the river. |
I've come around to this option being the nicest one. It's very Perlish and Strangely Consistent to do the right thing for the wrong reasons. 😉 |
When don't you want symbols and hygiene in this case? My guess is "never". You never don't want that. Or nearly never, like 99% never. So the next logical idea, inspired by Rust, is to use symbols by default in quasi blocks.
To be clear, we get to write the code that way, but the 007 compiler rewrites it as the version above with explicit usages of |
Looking at this with fresh eyes, I find that confusing. Even I'm reading the code, going "then why wouldn't it get set to The corresponding trick works with |
So let's use the |
In #207 (comment) we detail a need to sometimes declare variables in the mainline scope where the macro was called.
Here, let me rewrite the naïve implementation into something that does the right thing using this requested feature — an example speaks a thousand words, after all:
My initial thought was not the above syntax at all, but a builtin (say,
compilingScope()
) which gave you access to an object with three methods:declareVar
(which would runRuntime.pm
's declare-var method under the hood)getVar
, dittoputVar
, dittoBut the
COMPILING::
syntax gets us much closer to what S06 wants, and has the added advantage that we see clearly that it's "regular" variables we're dealing with, so we're declaring, reading, and writing them the regular way.The
[active]
syntax is part of the name (see #250), and is the way for us to interpolate a symbol into a longer name. It's inspired by ES6's "computed property key" syntax. In Perl 6, it'd be written as$::("COMPILING::{$active}")
or some such. The thing that goes inside the[]
can be a symbol or a string, but only symbols give that special warm gensym buzz.I guess for consistency we should also allow
my [someSymbol];
to work. Though offhand I don't see a use case for declaring variables with symbols in your own scope.The text was updated successfully, but these errors were encountered: