So if I double-wrap the QuoteNode like this, one gets through the escaping process:
return QuoteNode(Expr(:$, QuoteNode(toquote)))
That gives the expected (?) behavior:
julia> @sexpr (:if, (2 < 3), $(QuoteNode(Expr(:call, :f, :x, Expr(:$, :y), :z))))
:(if 2 < 3
$(QuoteNode(:(f(x, $(Expr(:$, :y)), z))))
end)
julia> cons(ans, :(f(z,c,z)))
:(if 2 < 3
$(QuoteNode(:(f(x, $(Expr(:$, :y)), z))))
else
f(z, c, z)
end)
julia> eval(ans)
:(f(x, $(Expr(:$, :y)), z))
julia> eval(ans)
syntax: "$" expression outside quote
julia> @sexpr (:if, (2 < 3), ~(f(x,$y,z)))
:(if 2 < 3
$(QuoteNode(:(f(x, $(Expr(:$, :y)), z))))
end)
julia> cons(ans, :(f(z,c,z)))
:(if 2 < 3
$(QuoteNode(:(f(x, $(Expr(:$, :y)), z))))
else
f(z, c, z)
end)
julia> eval(ans)
:(f(x, $(Expr(:$, :y)), z))
julia> eval(ans)
syntax: "$" expression outside quote
Now ~
acts like the manual’s example:
julia> @sexpr (~($(1+2)))
:($(QuoteNode(:($(Expr(:$, :(1 + 2)))))))
julia> eval(eval(ans))
syntax: "$" expression outside quote
julia> QuoteNode(Expr(:$, :(1+2)))
:($(QuoteNode(:($(Expr(:$, :(1 + 2)))))))
julia> eval(eval(ans))
syntax: "$" expression outside quote
Welp. I’m still not sure what QuoteNode
is good for, but nevertheless, the macro now produces them. If I ever come up with an application for this, I’ll let y’all know right away.