# Using Symbol within function (unexpected behaviour)

**URL:** https://discourse.julialang.org/t/using-symbol-within-function-unexpected-behaviour/24029
**Category:** New to Julia
**Created:** [May 9, 2019, 12:55pm UTC](https://discourse.julialang.org/t/using-symbol-within-function-unexpected-behaviour/24029 "2019-05-09T12:55:53Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)
#### Post date: [May 9, 2019, 1:40pm UTC](https://discourse.julialang.org/t/using-symbol-within-function-unexpected-behaviour/24029/2 "2019-05-09T13:40:15Z")

</div>

`eval()` always operates in _global scope_. Check out the help text:

```nohighlight
help?> eval
...

  eval(expr)

  Evaluate an expression in the global scope of the containing module. ...

```

Since `eval()` operates in global scope, it does not have access to the values of your local variables.

Since Julia 1.1, though, we have the `Base.@locals()` macro, which gives you a dictionary mapping local variable names to their local values. Your use case might be a good fit for that:

```julia
julia> function foo()
         a = 1
         println(Base.@locals())
       end
foo (generic function with 1 method)

julia> foo()
Dict{Symbol,Any}(:a=>1)

```

---

_[View the full topic](https://discourse.julialang.org/t/using-symbol-within-function-unexpected-behaviour/24029)._
