This is a beginner question but I had some trouble finding an answer in the documentation (or on StackOverflow) and I think it will be helpful to others as well. The question is simple:
How does a Julia macro call know when the arguments to the macro are done?
When brackets are used to mark the arguments, it should be straightforward (I think...). However, in the other case it seems more subtle. I suspect it has something to do with "number of expressions" (this potentially being a slightly tricky concept in itself) but I'm not sure and I want to have the documented official rule.
Some examples of why I think this is not obvious:
julia> macro a(arg...)
print(arg)
end;
julia> @a gg=3 if true # the :(gg = 3) is the first argument of the macro
print("val")
a = 1;;; # the macro does not see the semicolons (which makes sense to me)
end # the if statement is the second argument of the macro
# note: replacing "true" by "@a true" makes the number of arguments of
# the second macro depend on the following newline being there or not
# next: the first two assignments are two arguments. The last assignment is not an argument at all
julia> @a a = 4 f=3; aaa = "asdf"
julia> @a af = 4 (f=3; aaa = "asdf") # two arguments; the second one is a quote block
julia> @a af = 4; (f=3; aaa = "asdf") # one argument.
# edit:
julia> @a @a aa # One argument, counterexample to last claim
(:(#= REPL[37]:1 =# @a aa),)
Is it possible, for example, to have two consecutive if blocks as separate arguments?
One rule I seem to notice is that (when not using parentheses to enclose arguments) any macro call with more than one argument becomes invalid syntax if the macro part (@a) is removed. Is this true in general?
edit: No, see counterexample in code snippet.