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
if name == "huey" || name == "dewie" || name == "louie" {
}
Somewhat repetitive. Perl 6 allows us to write the equivalent of this:
if name == "huey" | "dewie" | "louie" {
}
or
if name == any("huey", "dewie", "louie") {
}
Essentially making the "or" logic operator subordinate to the comparison operator.
Perl 6 does this through a new type in the type system: Junction. But what if we were to try making it a purely syntactic construct in 007?
In #158, there's a mention of each maybe being subordinate to a Q::Statement. That is, it doesn't really make sense outside of a Q::Statement context. Similarly (it seems to me), the above | and any would not make sense outside the context of an operator that tries to determine the truth of something. In 007 currently, these operators qualify:
== != < <= > >= ~~ !~~ %%
(All comparison operators, plus infix:<%%>.)
In Perl 6 terms, 007 junctions would "collapse" immediately into a boolean. And they would only work if somewhere above them in the expression tree they found one of the above operators.
It's still an open question how such an inside-out macro would look. But two things would be very convenient (but not strictly necessary):
If the macro itself got the surrounding operator as a parameter.
If we had an AST-transforming helper function or method that could distribute the op among the arguments/operands.
I think there's a market for this kind of inside-out macros. Now that I'm thinking of them like that, I will stay on the lookout for them.
Oh, and in a perfect world, we'd probably want a protocol so that an operator can declare itself to be in the group above, so that these junctional macros are able to play well with user-defined operators.
The text was updated successfully, but these errors were encountered:
Somewhat related to #158.
Consider this code:
Somewhat repetitive. Perl 6 allows us to write the equivalent of this:
or
Essentially making the "or" logic operator subordinate to the comparison operator.
Perl 6 does this through a new type in the type system:
Junction
. But what if we were to try making it a purely syntactic construct in 007?In #158, there's a mention of
each
maybe being subordinate to aQ::Statement
. That is, it doesn't really make sense outside of aQ::Statement
context. Similarly (it seems to me), the above|
andany
would not make sense outside the context of an operator that tries to determine the truth of something. In 007 currently, these operators qualify:(All comparison operators, plus
infix:<%%>
.)In Perl 6 terms, 007 junctions would "collapse" immediately into a boolean. And they would only work if somewhere above them in the expression tree they found one of the above operators.
It's still an open question how such an inside-out macro would look. But two things would be very convenient (but not strictly necessary):
I think there's a market for this kind of inside-out macros. Now that I'm thinking of them like that, I will stay on the lookout for them.
Oh, and in a perfect world, we'd probably want a protocol so that an operator can declare itself to be in the group above, so that these junctional macros are able to play well with user-defined operators.
The text was updated successfully, but these errors were encountered: