How do I make a vector of symbols using a macro?
Expr(:vect, :x1, :x2)
ERROR: UndefVarError: x1 not defined
Clearly this making the expression
[x1, x2]. However I would like to make the vector
[:x1, :x2]. I can’t figure out how to make this work, can someone help me out?
Is this what you are looking for?
julia> macro foo()
Expr(:vect, Symbol(x1), Symbol(x2) )
@foo (macro with 1 method)
I think the insight you’re missing is how to use
QuoteNode to deal with the distinction between symbols (since every identifier is just a symbol in an Expr object) and quoted symbols:
Expr(:vect, QuoteNode(:x1), QuoteNode(:x2))