-
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
Kill off Q::Unquote #334
Comments
I'll just pop in and say that it's not obvious how we should do this. Needs more design. |
Here's a first stab at a design: if a quasi is meant to become a function (taking as inputs the concrete epressions to fill the unquotes with and returning as output a complete Qtree) then to a first approximation that function should:
Most of this is straightforward. There is one special case that's... a little bit tricky — operators and precedence. I think the easy way to say this is that we don't have enough information, in the general case to build a tree out of the terms and operators in an expression, if it contains an operator unquote. The missing operator contains vital information about precedence and associativity that might determine the final shape of the expression tree. If the above paragraph sounds like it contains a lot of hedging, it's because I really haven't thought this through all the way. But the simplest way forward seems to me to be to store expressions in a kind of "intermediate" form in the quasi function, and to do the precedence calculation only after splicing in the operator unquotes. For simplicity, I suggest we do this for all expressions at first. Later we can optimize that if we feel it matters. In practice it shouldn't make a noticeable difference unless maybe the number of macro expansions is enormous. |
I might be treading into premature optimization territory here, or just demonstrating the limits of my own imagination. But anyway, I can imagine uses for macros that can return one of several expressions, depending on arguments they're called with. I can imagine uses for macros that can be called with one of several operators. I'm failing to imagine circumstances where:
"Oh, yeah, um, this whole thing can straight-up parse differently depending on the precedence and associativity of the operator you give it. ... Of course it works correctly with every possible precedence level and associativity direction. We wrote exhaustive unit tests!" So, I'm really content with the possibility that a quasi might only be able to return one expression tree shape, and that macro authors who need several shapes will have to write several quasis and a switch statement. "Pluripotent stem quasis" might turn out to be the costly and unnecessary offspring of a Perl 5 source filter and an SQL injection attack. |
Thank you, that's a good bit of feedback. I need to let it simmer for a while. For now, two things:
|
This is the issue people usually have with C macros ( |
@vendethiel That makes a lot of sense. I will chalk that up as an argument for making unquoted operators maximally loose. I like the appeal to the AST being a tree. No-one would be happier than me if we ended up implementing a model that's radically simpler than extreme late-binding of unquoted operator precedence. So I will definitely be inclined to listen to arguments for simplifying the model. |
Unquotes aren't a type of AST node. They're a type of nothing, an un-thing, a nonexistence, like Dementors or The Nothing or whatever's outside the wall in Mario Kart.
The exact reasoning is described here: one, two, three, four, five. But tl;dr: a quasi is less like an AST fragment and more like a function/lambda expression containing instructions for how to build an AST. The parameters are the expressions in the unquotes.
Since we know that this is the model we have to converge on, we should switch 007 over to it, the sooner the better.
The text was updated successfully, but these errors were encountered: