Parsing expressions into functions

Why can’t you hit global scope in between the eval and calling of the ODE solver?

str = "x[1]*x[2]^2" # read from file
@eval f(x) = $(Meta.parse(str)) # define the function

# pass `f` to some routine

Otherwise, you can do as you do, but need to use invokelatest.

Each function has a different type so this won’t help. You need to use FunctionWrappers.jl for that usecase.

3 Likes