I’m having trouble with passing redefined functions as arguments of other functions (in my case, constantly redefined objetive functions to a minimizing method). The following behavior is observed in kernels 0.5.0 and 0.6.0-dev but not in 0.4.7 (I’m running a jupyter notebook at juliabox.com).
A minimal example is the following:
h(f::Function, n::Int) = f() + n # Define a function taking some arguments f() = 10 # Define a function to be passed as argument h(f,1) # This output 11 correctly
But if now we redefine “f”:
f() = 20 h(f,5) # This output 15!
That is, the function h takes n correctly but not the new function f (it should return 25).
For now, my solution is working on 0.4.7 but I wonder if there is an explanation for this behaviour (I already read this for example, but there is not a clear response).