-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Execute while and until inside macros #10959
base: master
Are you sure you want to change the base?
Conversation
Note that I excluded these from the macro language because they allow the compiler to hang. I'm not sure we should add this. |
At some point I was experimenting with a macro that could generate SQL from almost arbitrary expressions and on a part of it I ended up with this piece of code: {%
stack = ...
forever = [nil] of NilLiteral
forever.each do
forever << nil
top = stack.last
if top.is_a?(NilLiteral)
forever.clear
else
# do stuff that might involve pushing to "stack"
end
end
%} Yeah, it hurts my eyes too. But the point is: it is already possible to make infinite loops and consume unrestricted memory from macros. This PR doesn't make things worse, just cleaner and more obvious. |
It's true |
This should be good for review. |
I'm not sure about this. For example, I would expect such macro loops to have a block macro body similar to the {% while v < 5 %}
{% v += 5 %}
{% end %} That doesn't exclude the inline syntax implemented in this PR. But it's definitely more limiting in what can be expressed. I'd rather look at the bigger picture with a focus on implementing loops with a block body. The short form might be an enhancement, but it's not a priority. |
I have a working prototype of a At the moment, I was just playing with this small thing, but at some point I'll make a proper PR with everything that is missing ( |
Resolves #9091 (comment)