I’m having trouble with using quote. I have the following piece of code embedded into a larger code
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
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).