How can I define a julia macro that defines a macro?

Viewed 612

I would have thought this would work:

macro meta_meta(x,y)
  :(macro $x(arg) :($($y) + $arg) end)
end

The expected behavior is that calling @meta_meta(f,2) should be equivalent to macro f(arg) :(2 + $arg) end

In other words:

julia> @meta_meta(f,2)
julia> @f(3)
5

Instead I get:

ERROR: syntax: invalid macro definition

I'm at a bit of a loss for how to proceed. I see that the expression tree for this macro is different from the one I get if I manually generate @f and examine its expression tree, and I've tried several iterations of @meta_meta, but I cannot figure out how to change my definition to get it working.

1 Answers
Related