The quasi in the example name.alma doesn't need to take a closure
masak opened this issue · 0 comments
masak commented
macro name(expr) {
if expr ~~ Q.Postfix.Property {
expr = expr.property;
}
assertType(expr, Q.Identifier);
return quasi { expr.name };
}
my info = {
foo: "Bond",
bar: {
baz: "James Bond"
},
};
say(name(info)); # info
say(name(info.foo)); # foo
say(name(info.bar.baz)); # baz
I was re-watching a talk I made in 2018 and I saw this code, and I realized how extravagant return quasi { expr.name }
really is. I mean, it works, but at the cost of inserting a property lookup into the macro-expanded code, keeping the expr
AST node alive until runtime, just to do that lookup.
Suggest replacing the final return with this:
my name = expr.name;
return quasi { name };