Escaping expressions within macro calls

Macros are actually special here, because quoted macrocalls in other macros get expanded inside that macro’s definition, not inside its caller. So in this case @foo is already expanded inside @macro3, that’s why there’s no need for lowering to make it a GlobalRef. This should illustrate what is going on:

julia> macro m()
           @show __source__
           @show (@__LINE__, @__FILE__)
           :(@__LINE__, @__FILE__)
       end
@m (macro with 1 method)

julia> @m
__source__ = :(#= REPL[2]:1 =#)
(#= REPL[1]:3 =# @__LINE__(), #= REPL[1]:3 =# @__FILE__()) = (3, "REPL[1]")
(4, "REPL[1]")

Does that help?

2 Likes