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
Implement conditional/ternary/trinary operator (?? !!) as an 'is parsed' macro #163
Comments
I'm very interested to know if you have any idea how is parsed/tighter-looser will interact. Because I can't think abouit at all |
I think the simplest way to phrase it is "they don't interact". For example, the fact that we make an operator
And never in term position, like:
On the post-conditions side — again because
When it comes to handling precedence (and associativity), the special parsing is a black box. It doesn't matter what happened inside of the I'm confident that this will work out pretty well, because that's how it already works in Rakudo's Hope that answers it! I remember I/we were struggling with these bits in #18. That issue ended up being rejected with this parting message:
Which is what is happening in this issue. 😄 |
Thanks for the clarification! |
Just a quick addition:
Which will have the consequences that when someone later inspects the Qtree of a program with a This is important because to the extent we consider some built-in operators as having been defined "in code" (at least in theory), then they'd also need this mechanism. But it's just as important for some custom things who want to look built-in to have this mechanism. Presumably there'd be some way to ask the |
In the case of a missing
|
I had two scattered thoughts today:
The implementation in the OP has exactly the three parameters necessary for that to work; i.e. it'd simply be
|
Although Future Me is not 100% convinced this is a good idea, when I saw the suggestion here to support a kind of "reference transform", I thought about this quasi-use-case of making I was going to say that this maybe requires some degree of static typing... but maybe not. What it does require is a kind of "lvalue-ready invocation" (as Bel does) of the function/operator, which can be done at the last minute by the evaluator. Of course, in that case, one also gets a runtime error if the function returns something too rvalue-ish; this error in turn could be shifted left to compile time by a sufficiently static analysis — but it's not a requirement. |
007 is hanging its head in shame over its lack of a ternary operator. The only way to restore its name to glory is to implement it in style, namely as an
is parsed
macro.Here's my best take at how it'd look:
Some thoughts:
/.../
for regexes in 007. But it's the lazy/obvious default.<EXPR>
things to the parameters in the macro. I'm not sure what the mechanism should be. For now, I've gone with the simplest possible, saying they bind in order, disregarding names and stuff. This is probably too simplistic; we might want to do something closer to the kinds of binding$/
does.condition
andelse_part
at all;condition
has already been parsed at this point, and gets sent into the macro as a courtesy because it's aninfix
.else_part
will simply be parsed as the rhs of the infix.Match
objects, in 007 they are Qnodes.=
isn't included between the??
and the!!
. In Rakudo, this is done by calling<EXPR>
at a certain precedence level (<EXPR('i=')>
), and then checking if there's an infix. We might want to do it like that; calling into<EXPR>
at a certain precedence level is probably something 007 wants to do sooner or later anyway.<EXPR>
and then post-analyze it for=
. But that's probably not going to fly, since parentheses don't have aQ
representation. I guess this use case is a (weak) argument for parentheses having a Q. But then we'd probably also need acircumfix
operator category...=
after the!!
should not be parsed as part of the rhs. This falls out of normal precedence, though.Seeing the above, I'm pleasantly surprised at how little additional machinery would be needed for this. Basically we'll need regex support, which we can start playing with under a feature flag today if we want. The rest we can hard-code to various degrees in the short run.
I had no idea whether we currently even allow the definition of an infix routine with spaces in it. Turns out not only do we allow it, but we parse it as an operator, too!
I'm not sure how I feel about that. It will need some kind of whitespace-related ruling at some point.
The text was updated successfully, but these errors were encountered: