With a hand-crafted Expr, I can initialize a new variable like so:
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> 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