I want to define a bunch of macros that define function methods in a private module.
module MyModule
function f() end
function g() end
end
using Main.MyModule
struct T
i
end
macro f(T, expr)
esc(:(MyModule.f(::$T) = $expr))
end
@f T "test"
julia> MyModule.f(T(1))
"test"
That works fine if I do it manually. If I try to do this in an eval loop, if fails
for fn in (:f, :g)
Core.eval(@__MODULE__, quote
macro $fn(T, expr)
esc(:($(MyModule.$fn)(::$T) = $expr))
end
end)
end
The macro call fails:
julia> @f T "test"
ERROR: syntax: invalid function name "MyModule.f" around REPL[36]:1
Stacktrace:
[1] top-level scope
@ REPL[36]:1