#####################
#IMPLEMENTATION CODE:
#####################
module Y
export modify
"""
A LOT OF CODE HERE, REMOVED FOR SIMPLICITY
"""
function _modify(expr)
is_lambda,f,args,body = decompose_function(expr)
if is_lambda
quote
($(args...)) -> $(transform(body))
end
else
quote
function $(esc(f))($(args...))
$(transform(body))
end
end
end
end
macro modify(func)
_modify(func)
end
end
#####################
#USAGE CODE:
#####################
module X
using Y
type Arg{T}
x::T
end
println(macroexpand( quote
@modify function f(x::Arg{Bool})
y = 12
if x
y+1
else
y-1
end
end
end))
end
#####################
#GENERATED CODE:
#####################
begin
begin
function f(#22#x::Y.Arg{Y.Bool})
begin
#21#y = 12 #
begin
"LOTS OF CODE HERE"
end
end
end
end
end
#########################
#QUESTION
#########################
In the generated code, the argument Arg{Bool} is treated as if it is an
element of module Y, but it is an element of module Y. So when the code
executes, the interpreter complains and says:
ERROR: LoadError: UndefVarError: Arg not defined
Why $(args...) in the implementation code doesn't work?
Thanks