Skip to content
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 junctions as syntactic constructs through inside-out macros #210

Open
masak opened this issue Dec 11, 2016 · 0 comments
Open

Implement junctions as syntactic constructs through inside-out macros #210

masak opened this issue Dec 11, 2016 · 0 comments

Comments

@masak
Copy link
Owner

masak commented Dec 11, 2016

Somewhat related to #158.

Consider this code:

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant