-
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
Implement infix:<ff> and family #207
Comments
I think this is a correct implementation of
Right now it fails with this error on |
Removed the "low-hanging-fruit" label, since this issue is blocked on another. |
This won't happen on its own. Why? Because the macro will be called exactly once, at parse time, and so there will be only one "instance" of the variable (See the test at the end of OP.) I'm not clever enough today to nail down how this ought to work. But it needs to be something that re-enters the scope with the |
Thinking about this a bit more, I'm struck by the fact that the semantics we want is as if This is exactly the mechanism proposed by S06 as |
And for when we feel up to solving the concerns about un-hygiene satisfactorily, there's a well-tested solution out there: EcmaScript 6 Symbols:
This has everything we need:
I don't know the exact relation/history between (EcmaScript) symbols and (Lisp) gensyms, but I feel pretty comfortable I understand symbols. I think we want something like that when we install state-managing variables in scopes not owned by the macro itself. |
I was toying around with having a class-based API for stateful macros. The
I don't know if thinking about macros as classes is fruitful in any way. To be honest I expected the class to be a better fit than the macro+quasi, but the latter is shorter and no less clear. Maybe the only interesting thing about it is that it brings us quite close to how we currently implement 007 operators with the macro nature in Perl 6. (But even that might change with #185.) |
|
I'll have to take my November me's word for it that the
I haven't looked in detail, but I'm fairly certain why this happens. The two occurrences of
are going to be "dragged" into the But the two macro operands In other words, we should look into wrapping the unquoted things in a Go team hygienic macro! |
We didn't have function terms until 5865342, and the check function apparently never dove into them. Now that it does, it allows the initial reported wrong line of #212 to run just fine: $ bin/007 -e='macro moo(x) { return quasi { (func() { my y = {{{x}}} })() }; }; say(moo(42))' 42 I think #212 can be closed now, but going to have a look around and try to run everything in it, and also check out #207 which I know was affected by this, and also think through what check might be missing.
But today, I am! 😄 The solution has been staring me in the face. I'm busy, so I'll just leave this here. Current implementation (from examples/ff.alma):
Correct implementation:
Re-opening so that we can fix this. |
Just dropping in here to point out a connection — previously not pointed out, I believe — between the statefulness of the |
Eight operators in total:
ff ff^ ^ff ^ff^ fff fff^ ^fff ^fff^
.I dunno why we haven't done these long ago. They are the perfect poster child for macros. As far as I can see, we can do them already. Also, I'd say they're a perfect example to have in the new
examples/
directory. (See #194.)The reason they're perfect is that they are actually operators with internal state. If we implement this right, the operator state should be per sub clone. See these tests from the spectest suite:
The text was updated successfully, but these errors were encountered: