# Is it possible to work with eval(:(x=10)) without touching a global/modules scope

**URL:** <https://discourse.julialang.org/t/is-it-possible-to-work-with-eval-x-10-without-touching-a-global-modules-scope/59729>\
**Category:** General Usage\
**Created:** [April 21, 2021, 11:49am UTC](https://discourse.julialang.org/t/is-it-possible-to-work-with-eval-x-10-without-touching-a-global-modules-scope/59729 "2021-04-21T11:49:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)\
**Post date:** [April 21, 2021, 11:49am UTC](https://discourse.julialang.org/t/is-it-possible-to-work-with-eval-x-10-without-touching-a-global-modules-scope/59729/1 "2021-04-21T11:49:50Z")

</div>

Hi,

is there a way to make this code work without messing up the global namespace?

```julia
x = 10
function f()
  eval(:(local x = 20))
  return eval(:x)
end
f()
@assert f() == 20
@assert x == 10

```

This is a minimal example for my real problem. Basically, I want to parse some TOML files and allow the user to refer to do stuff like this:

```nohighlight
[cell]
x = "rand()"
y = "cell.x + rand()"

```

I figured out a nice way to do that, with the only problem that it messes with the global (or a modules) variables.

---

<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 21, 2021, 11:59am UTC](https://discourse.julialang.org/t/is-it-possible-to-work-with-eval-x-10-without-touching-a-global-modules-scope/59729/2 "2021-04-21T11:59:52Z")

</div>

It is a bit unclear what you want to do but you cannot dynamically introduce local variables (with e.g. `eval`) in any way.

---

<div class="post-metadata">

**Author:** ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)\
**Post date:** [April 21, 2021, 12:01pm UTC](https://discourse.julialang.org/t/is-it-possible-to-work-with-eval-x-10-without-touching-a-global-modules-scope/59729/3 "2021-04-21T12:01:36Z")

</div>

Thanks for the reply. That answers my question!

I will think about other ways to solve my original problem and then post a separate question with more info.

---

<div class="post-metadata">

**Author:** ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)\
**Post date:** [April 21, 2021, 1:04pm UTC](https://discourse.julialang.org/t/is-it-possible-to-work-with-eval-x-10-without-touching-a-global-modules-scope/59729/4 "2021-04-21T13:04:28Z")

</div>

I found a solution for my problem using regular replace(…). (Should have kept it simple from the beginning 😃 )
