# Evaluating Expr Error: UndefVarError: = not defined

**URL:** <https://discourse.julialang.org/t/evaluating-expr-error-undefvarerror-not-defined/29458>\
**Category:** General Usage\
**Created:** [October 3, 2019, 5:57pm UTC](https://discourse.julialang.org/t/evaluating-expr-error-undefvarerror-not-defined/29458 "2019-10-03T17:57:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex\_Ellison](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alex_ellison/32/5749_2.png) [@Alex\_Ellison](https://discourse.julialang.org/u/Alex_Ellison)\
**Post date:** [October 3, 2019, 5:57pm UTC](https://discourse.julialang.org/t/evaluating-expr-error-undefvarerror-not-defined/29458/1 "2019-10-03T17:57:30Z")

</div>

With a hand-crafted Expr, I can initialize a new variable like so:

```julia
julia> a = :(x=1)
:(x = 1)

julia> eval(a)
1

julia> x
1

julia> 

```

However, if I evaluate a comparably simple Expr generated from the Reduce algebra library I get the following problematic behavior:

```julia
julia> begin
       using Reduce
       a = :(2*(x+y))
       b = :(2*x + 2*y)
       # solve returns a tuple of solutions
       c_expr = Algebra.solve(:($a / $b == c), :(c))[1]
       println(typeof(c_expr))
       println(c_expr)
       eval(c_expr)
       println(c)
       end
Expr
c = 1
ERROR: UndefVarError: = not defined
Stacktrace:
 [1] top-level scope at none:0
 [2] eval at ./boot.jl:328 [inlined]
 [3] eval(::Expr) at ./client.jl:404
 [4] top-level scope at none:9

julia> 
ERROR: LoadError: TypeError: in Expr, expected Symbol, got Expr
Stacktrace:
 [1] Expr(::Any, ::Vararg{Any,N} where N) at ./boot.jl:221
 [2] top-level scope at none:0
in expression starting at /Users/alex/dev/spectral/derp.jl:8
help?> eval
search: eval evalfile evallhseq @eval @evalpoly @evallhseq @off_evallhseq bytesavailable readavailable

  eval(expr)

```

We can see it’s an Expr, and we can see it is `c = 1`. This seems completely analogous to the working input above. What gives?  
Thanks

---

<div class="post-metadata">

**Author:** ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)\
**Post date:** [October 3, 2019, 6:07pm UTC](https://discourse.julialang.org/t/evaluating-expr-error-undefvarerror-not-defined/29458/2 "2019-10-03T18:07:13Z")

</div>

It seems this here is the problem

```nohighlight
julia> c_expr = Algebra.solve(:($a/$b == c),:c)[1]
:(c = 1)

julia> dump(ans)
Expr
  head: Symbol call
  args: Array{Any}((3,))
    1: Symbol =
    2: Symbol c
    3: Int64 1

julia> :(c=1) |> dump
Expr
  head: Symbol =
  args: Array{Any}((2,))
    1: Symbol c
    2: Int64 1

```

Probably due to the fact that the Julia language has changed at some point, this can be fixed.

---

<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:** [October 3, 2019, 6:07pm UTC](https://discourse.julialang.org/t/evaluating-expr-error-undefvarerror-not-defined/29458/3 "2019-10-03T18:07:56Z")

</div>

Call `dump` on the expression. How things print can be deceiving.

Edit: nvm, sniped.

---

<div class="post-metadata">

**Author:** ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)\
**Post date:** [October 3, 2019, 6:21pm UTC](https://discourse.julialang.org/t/evaluating-expr-error-undefvarerror-not-defined/29458/4 "2019-10-03T18:21:49Z")

</div>

The bug has now been fixed, this shouldn’t be a problem anymore.

[https://github.com/chakravala/Reduce.jl/commit/91b976288063d5fdb6e617a538aa5cc093d83e3b](https://github.com/chakravala/Reduce.jl/commit/91b976288063d5fdb6e617a538aa5cc093d83e3b)

---

<div class="post-metadata">

**Author:** ![Alex\_Ellison](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alex_ellison/32/5749_2.png) [@Alex\_Ellison](https://discourse.julialang.org/u/Alex_Ellison)\
**Post date:** [October 3, 2019, 6:36pm UTC](https://discourse.julialang.org/t/evaluating-expr-error-undefvarerror-not-defined/29458/5 "2019-10-03T18:36:24Z")

</div>

Confirmed, it works, thanks, @chakravala !
