Hi fellows,
I was coding a macro, and I am having a prefix issue with functions.
basically the problem is: Every single one of available functions
(_ex_func) which i want to be globally accessible are prefixed with the
name of the module(X) in which the macro f is defined
Here is the code example:
julia> module X
export @f
macro f(x)
st = string("_",x)
sy = symbol(st)
esc(quote
function ($sy)()
println("st")
end
function ($(symbol(string("_1",x))))()
($sy)()
println("sty")
end
export $sy
export $(symbol(string("_1",x)))
end
)
end
@eval @f ex_func
end
X
julia> using X
julia> _
_1ex_func __precompile__ _ex_func
julia> _1ex_func.env.defs.func.code
AST(:($(Expr(:lambda, Any[], Any[Any[],Any[],0,Any[]], :(begin # none,
line 12:
*(X._ex_func)() # none, line 13: # i want this to be not prefixed
by X*
return (X.println)("sty")
end)))))
julia> macroexpand(:(@f ex_func))
quote # none, line 7:
function _ex_func() # none, line 8:
println("st")
end # none, line 11:
function _1ex_func() # none, line 12:
*_ex_func() # none, line 13: # it seems OK, here!!!*
println("sty")
end # none, line 15:
export _ex_func # none, line 16:
export _1ex_func
end
as you may see , I may well define _ex_func in other modules and use it
from the function X._1ex_func().
But this prevents me doing it.
How can i solve this problem?
Thanks