unfortunately I face severe problems when dealing with macros with nested quotes. Somehow the standard hygiene does not seem to work… three examples, all failing
first experiment … fails
module NestedQuoteHygiene
export @hygienetest
macro hygienetest()
quote
function a end # hygiene
nestedquote = quote
println(a) # no hygiene, i.e. refers to another a
end
(nestedquote, a)
end
end
end
when running this macro test, you can see that the a
within the nested quote is not renamed accordingly
julia> NestedQuoteHygiene.@hygienetest
(quote
println(a)
end, #8#a)
What do I do wrong?
I really want to refer to the a
function defined in the macro, i.e. #8#a
second experiment … failing
I made a second test which looks even more surprising - this is interpolating a
now
module NestedQuoteHygiene2
export @hygienetest2
macro hygienetest2()
quote
function a end # hygiene
nestedquote = quote
println($a) # no hygiene, i.e. refers to another a
end
(nestedquote, a)
end
end
end
run it like
julia> a = 4
4
julia> NestedQuoteHygiene2.@hygienetest2
(quote
println(4)
end, #8#a)
that looks really bad… any idea?
third experiment… also failing
module NestedQuoteHygiene3
export @hygienetest3
macro hygienetest3()
quote
function a end # hygiene
symbol_a = Symbol(a)
nestedquote = quote
println($symbol_a) # ERROR: UndefVarError: symbol_a not defined
end
(nestedquote, a)
end
end
end
julia> NestedQuoteHygiene3.@hygienetest3
ERROR: UndefVarError: symbol_a not defined
anyone who can help?
EDIT Clarification of Goal: I want to refer to function a end
from the inner quote
any help is highly appreciated… this really blocks me currently