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
defbla1(*args1, **args2)
p args1
p args2
endmacrobla2(*args1, **args2)
bla1(*{{args1}}, **{{args2}})
end
bla2(1, a:1) # => ok
bla2(1, 2) # => Syntax error in expanded macro: bla2:1: for empty hashes use '{} of KeyType => ValueType'
bla2(a:1) # => Syntax error in expanded macro: bla2:1: for empty hashes use '{} of KeyType => ValueType'
The text was updated successfully, but these errors were encountered:
You can splat inside a macro. And in master you can now double splat inside macros. It's still a bit annoying because if args1 is empty there will be a comma at the beginning and it will fail to parse, but it's still possible.
We also have an argify method which the same as splatting (*), maybe we can add an argument to it that is a string to append if it's not empty. So...
macrobla2(*args1, **args2)
bla1({{args1.argify(", ")}} {{**args2}})
end
What do you think? I needed that argify method with an optional trailing comma a couple of times now. We should probably renamed it to splat, though, and have a double_splat method too.
To be honest, I'm not super happy with the way macros currently work (or are implemented), though they usually get the work done. Before 1.0 we'll discuss better alternatives to implement them.
firejox
pushed a commit
to firejox/crystal
that referenced
this issue
Dec 12, 2016
The text was updated successfully, but these errors were encountered: