Defining function from string with parse and eval failure in v0.6 master


The following seems like a bug, but maybe there is something I am missing about eval and parse that is causing the failure.
I define anonymous function and pass it as a parameter to another function. The code works when the anonymous function is defined directly as lambda, but fails when it is defined with parse and eval.

Contest of my file “test_func.jl”

function foo1()
    return (x,y)->(x==y)

function foo2()
   return eval(parse("(x,y) -> (x==y)"))

function foo3(f, x,y)    

# this works with function defined directly as lambda in foo1

# this works with foo2 returning a function defined with parse and eval

# this fails with the parse and eval defined function passed directly as parameter to another function

This is with master from build today.

   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation:
   _ _   _| |_  __ _   |  Type "?help" for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.6.0-pre.beta.180 (2017-04-16 23:46 UTC)
 _/ |\__'_|_|_|\__'_|  |  Commit 934e0e3 (0 days old master)
|__/                   |  x86_64-linux-gnu

julia> include("test_func.jl")
ERROR: LoadError: MethodError: no method matching (::##5#6)(::Int64, ::Int64)
The applicable method may be too new: running in world age 21669, while current world is 21670.
Closest candidates are:
  #5(::Any, ::Any) at none:1 (method too new to be called from this world context.)

You’re experiencing which is a breaking change in Julia v0.6. This change was made to avoid a long-standing issue in Julia in which newly-defined functions sometimes wouldn’t take effect: Julia v0.6 is stricter (which is annoying in your particular case) but also more correct (which is better in all cases).

It might be worth considering whether you really need to be defining a function with eval(). There may be an alternative that doesn’t require jumping through these hoops.


On the other hand, I admit I was very surprised to see that


works, but


does not, even when the code is put inside a script or module.

Ah, I see, the distinction between those two shows up only at global scope. Putting the calls to foo2() and foo3 inside a function results in


also failling, as expected.

Thanks, got it to work with the double eval after reading the manual.

This came up with experimenting with runtime defined functions from strings.