You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The idea is to be able to define a macro that makes this syntax legal.
my numbers = [1, 2, 3];
my squares = [ x <- numbers | x * x ];
Roughly, it'd happen something like this:
We define a macro term:<[>
It parses enough to find out if the first things after the [ are an identifier and an arrow <- (modulo whitespace)
If it isn't, then it defers control to the usual (right now hypothetical) term:<[> which knows how to parse normal arrays.
Assuming it succeeds, it parses the rest, and generates this code:
my res = [];
for numbers -> x {
res.push(x * x);
}
res;
What's necessary for this to work?
Macro terms
Built-in terms being (conceptually) macros too, so that we can defer to them
Some is parsed functionality
A defer mechanism (which, in a given sub or macro, physically substitutes the current call with a call to the sub or macro that was shadowed)
And, crucially,
A way to avoid infinite macro recursion when the [] is parsed in the code to be generated.
I can see two ways to do that last bit. Either we don't write quasi code at all for that (because it's too complicated anyway), or we simply pull out [] into a constant (EMPTY_ARRAY, say) before the macro, and use that.
The text was updated successfully, but these errors were encountered:
The idea is to be able to define a macro that makes this syntax legal.
Roughly, it'd happen something like this:
macro term:<[>
[
are an identifier and an arrow<-
(modulo whitespace)term:<[>
which knows how to parse normal arrays.Assuming it succeeds, it parses the rest, and generates this code:
What's necessary for this to work?
is parsed
functionalitydefer
mechanism (which, in a given sub or macro, physically substitutes the current call with a call to the sub or macro that was shadowed)And, crucially,
[]
is parsed in the code to be generated.I can see two ways to do that last bit. Either we don't write quasi code at all for that (because it's too complicated anyway), or we simply pull out
[]
into a constant (EMPTY_ARRAY
, say) before the macro, and use that.The text was updated successfully, but these errors were encountered: