Macro hygiene is a bit concise when using a quote inside a quote. Often I find that the only way is to completely abandon macrohygiene and use gensym for simulation.
However, in your example, it is just simple to include an internal quote in Expr :
julia> macro meta_meta(x, y) :(macro $(esc(x))(arg) Expr(:call, :+, $(esc(y)), esc(arg)) end) end @meta_meta (macro with 1 method) julia> @meta_meta f 2 @f (macro with 1 method) julia> @f 3 5
If things get more complicated, the approach I mentioned above includes disabling macro-aggregation using esc . This means that we must do hygiene ourselves, so gensym :
julia> macro meta_meta(x, y) arg = gensym() esc(:(macro $x($arg) :($$y + $$arg) end)) end @meta_meta (macro with 1 method) julia> @meta_meta f 2 @f (macro with 1 method) julia> @f 3 5
source share