How do you evaluate a parameter/variable if you are not in Main eval or Core.Eval do not work?

In Julia (unlike Matlab, Python, and other interpreted languages) you cannot eval inside the scope of a function. (When the function is running it has already been compiled into machine code.)

eval always runs in the global scope (that is: outside of the function) even when called from inside a function.

Inside of a function, you can use the @isdefined macro.

julia> function f()
             println(@isdefined x)
             x = 3
             println(@isdefined x)
         end
  f (generic function with 1 method)
  
  julia> f()
  false
  true
1 Like