This question builds the previous SO question , which was intended to build expressions from expressions inside a macro. Nevertheless, everything turned out to be a small trucker when quoting the entire expression. For example, I want to build an expression: (name = val). Following:
macro quotetest(name,val) quote nm = Meta.quot($(QuoteNode(name))) v = Meta.quot($(QuoteNode(val))) println(nm); println(typeof(nm)) println(v); println(typeof(val)) end end @quotetest x 5
displays
:x Expr $(Expr(:quote, 5)) Expr
showing that I'm on the right track: nm and val are the expressions I want inside the quote. However, at the moment I can not apply the previous solution. For instance,
macro quotetest(name,val) quote nm = Meta.quot($(QuoteNode(name))) v = Meta.quot($(QuoteNode(val))) println(nm); println(typeof(nm)) println(v); println(typeof(v)) println(:($(Expr(:(=),$(QuoteNode(nm)),$(QuoteNode(val)))))) end end
doesn't work saying nm is not defined . I tried just interpolating without QuoteNode , avoiding interpolating $(esc(nm)) , etc. I can't figure out how to get this to build an expression.
source share