# How to make a vector of symbols using a macro

**URL:** <https://discourse.julialang.org/t/how-to-make-a-vector-of-symbols-using-a-macro/42439>\
**Category:** Data\
**Created:** [July 2, 2020, 4:58pm UTC](https://discourse.julialang.org/t/how-to-make-a-vector-of-symbols-using-a-macro/42439 "2020-07-02T16:58:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [July 2, 2020, 4:58pm UTC](https://discourse.julialang.org/t/how-to-make-a-vector-of-symbols-using-a-macro/42439/1 "2020-07-02T16:58:48Z")

</div>

How do I make a vector of symbols using a macro?

```julia
macro foo()
    Expr(:vect, :x1, :x2)
end

julia> @foo
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?

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [July 2, 2020, 5:10pm UTC](https://discourse.julialang.org/t/how-to-make-a-vector-of-symbols-using-a-macro/42439/2 "2020-07-02T17:10:35Z")

</div>

Is this what you are looking for?

```julia
julia> macro foo()
           Expr(:vect, Symbol(x1), Symbol(x2) )
       end
@foo (macro with 1 method)

julia> @foo
2-element Array{Symbol,1}:
 :x1
 :x2

```

---

<div class="post-metadata">

**Author:** ![johnmyleswhite](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnmyleswhite/32/31_2.png) [@johnmyleswhite](https://discourse.julialang.org/u/johnmyleswhite)\
**Post date:** [July 2, 2020, 5:27pm UTC](https://discourse.julialang.org/t/how-to-make-a-vector-of-symbols-using-a-macro/42439/3 "2020-07-02T17:27:59Z")

</div>

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:

```julia
macro foo()
    Expr(:vect, QuoteNode(:x1), QuoteNode(:x2))
end

```
