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
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 };
The text was updated successfully, but these errors were encountered:
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 theexpr
AST node alive until runtime, just to do that lookup.Suggest replacing the final return with this:
The text was updated successfully, but these errors were encountered: