# Problem with quote

**URL:** <https://discourse.julialang.org/t/problem-with-quote/10484>\
**Category:** New to Julia\
**Tags:** metaprogramming\
**Created:** [April 22, 2018, 7:29pm UTC](https://discourse.julialang.org/t/problem-with-quote/10484 "2018-04-22T19:29:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mposs](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mposs/32/21087_2.png) [@mposs](https://discourse.julialang.org/u/mposs)\
**Post date:** [April 22, 2018, 7:29pm UTC](https://discourse.julialang.org/t/problem-with-quote/10484/1 "2018-04-22T19:29:15Z")

</div>

Hello

I’m having trouble with using quote. I have the following piece of code embedded into a larger code

```julia
X = rand(5)
println("X outside loops is $X")
loops = quote
        println("X inside loops is $X")
    end
println(loops)
eval(loops)

```

The code above returns the following when embedded into my larger code

```julia
X outside loops is [0.406786, 0.0431394, 0.563856, 0.946204, 0.135217]
begin # /home/mposs/Dropbox/Workspace/julia/MMMKnapsack/combi_k_meta.jl, line 225:
    println("X inside loops is $(X)")
end
ERROR: LoadError: UndefVarError: X not defined
while loading /home/mposs/Dropbox/Workspace/julia/MMMKnapsack/run_SP.jl, in expression starting on line 45

```

However, when run by itself, my piece of code works properly. Any hint why am I facing this? (It is hard to provide my full code here, unfortunately).

Michael.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [April 22, 2018, 7:38pm UTC](https://discourse.julialang.org/t/problem-with-quote/10484/2 "2018-04-22T19:38:01Z")

</div>

`eval` evaluates in global scope.

---

<div class="post-metadata">

**Author:** ![mposs](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mposs/32/21087_2.png) [@mposs](https://discourse.julialang.org/u/mposs)\
**Post date:** [April 22, 2018, 7:47pm UTC](https://discourse.julialang.org/t/problem-with-quote/10484/3 "2018-04-22T19:47:43Z")

</div>

Thank you!
