-
-
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
Block bodies in macros should always be Expressions #5258
Comments
If you want to pass one or many arguments to a macro, use a splat: print_methods(
def foo
end,
def bar
end
) I don't think we'll change macros to do what you want, it's counter-intuitive and expensive, and it changes what you send and what you print. |
Why is it counter-intuitive for a block body to ever be an expressions of size 1? |
macro foo(&block)
{{ block.body.is_a?(If) }}
end
foo do
if 1; 2; end
end Wouldn't it be counter-intuitive that the above gives |
In you example @asterite I think it is counter-intuitive to have: foo do
if 1; 2; end
end
# Gives true
foo do
if 1; 2; end
if 3; 4; end
end
# Gives false |
@asterite Absolutely not, it's counter-intuitive to me that that does work. And certainly less powerful. "A block body is an Expressions unless it's only one expression" is a lot more complex and introduces a lot more complexity (when you don't have the power of visitor classes) then "A block body is always an Expressions". |
I agree. It seems only reasonable that a macro body is always |
It would certainly break everything if we change methods like Instead I think we should define |
@HertzDevil Sounds reasonable. However, I'm wondering if we really need this on every |
Currently in macros, bodies of blocks of code can either be
Expressions
,Nop
, or any other type ofASTNode
- depending on how many expressions/ statements there are. This is the case for control flow, blocks, methods, etc. Iterating over the expressions is difficult as you have to check what type the body is before using it.This can be worked around, but the workaround gets tedious:
I think that the simplest / cleanest solution would be for the body to be an
Expressions
object, containing some number of nodes (zero or more). There could be a helper method to check if it is a no-op (ie it contains no elements in the list) which could replace the use of.is_a?(Nop)
.Crystal version (pretty close to master)
The text was updated successfully, but these errors were encountered: