# Pass expression to manipulate local variable

**URL:** <https://discourse.julialang.org/t/pass-expression-to-manipulate-local-variable/79652>\
**Category:** New to Julia\
**Tags:** question, metaprogramming\
**Created:** [April 18, 2022, 8:15pm UTC](https://discourse.julialang.org/t/pass-expression-to-manipulate-local-variable/79652 "2022-04-18T20:15:32Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![FireCrumb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/firecrumb/32/35370_2.png) [@FireCrumb](https://discourse.julialang.org/u/FireCrumb)\
**Post date:** [April 18, 2022, 8:35pm UTC](https://discourse.julialang.org/t/pass-expression-to-manipulate-local-variable/79652/2 "2022-04-18T20:35:39Z")

</div>

According to an answer in another thread

> `eval` always happens at _global scope_

So the question remains: how to pass an `Expr` to work on _local scope_?

> [@Metaprogramming & variable scope](https://discourse.julialang.org/t/metaprogramming-variable-scope/25819):
>
> I have some function as such: function somefunction(df::AbstractDataFrame, indexcols::Array{Symbol,1}) ... dummydf = similar(df,0) for col in indexcols dummydf[col] = [] @eval $col = unique(df[$(QuoteNode(col))]) end ... return dummydf end For the @eval statement in the for loop, it’s telling me that df is not defined. I’m guessing that it’s looking for df within the scope of the eval statement. I tried wrapping the df in QuoteNode, but that didn’t work either.…

---

_[View the full topic](https://discourse.julialang.org/t/pass-expression-to-manipulate-local-variable/79652)._
