Hi Fellows,
I was trying to return a module expression to be evaluated at the top module of where i do the macrocall. Here is an example:
module X
export @cmodule
is_module(a) = false
is_module(e::Expr) = e.head == :module
function make_top_level(e::Expr)
if e.head == :block && any( is_module.(e.args) )
Expr(:toplevel, e.args...)
elseif e.head == :block
Expr(:block, make_top_level.(e.args)...)
else
e
end
end
function create_module(name)
quote
module $name
end
end |> make_top_level
end
macro cmodule(name)
esc(create_module(name))
end
module Y
module Z
using X
#here if i do the following the new module will be X.Y.Z.MDD, but i want it to be X.MDD, How can i do that?
@cmodule MDD
end
end
end