Expression parser

julia> module UserCode end
Main.UserCode

julia> const UC = Main.UserCode
Main.UserCode

julia> include_string(UC, "x = 3; y = 4; z(x, y) = 2 + 3x - exp(-y)")
z (generic function with 1 method)

julia> x0, y0 = UC.x, UC.y
(3, 4)

julia> UC.z(x0, y0)
10.981684361111267

julia> z
ERROR: UndefVarError: z not defined

This is flexible but dangerous, as it allows the user to run arbitrary code. See this post for other approaches: Evaluate expression in function

2 Likes