-
-
Notifications
You must be signed in to change notification settings - Fork 228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Function redefinition problem #119
Comments
Hey, (the Julia core devs are working on making this nicer, but the infamous issue JuliaLang/julia#265 is getting in the way right now, but should be fixed on v0.6) However, there is an easy fix. Instead of using a function, you can use an anonymous function. These have no issues with function re-definitions. There is a short form: f = (t,u) -> (print(u); u) which is for writing one-line anonymous functions, and a long form: f = function (t,u)
print(u)
u
end for writing multi-line anonymous functions. Since v0.5, anonymous functions compile and therefore they have no performance disadvantage. Additionally, if you need to write extra dispatches on an anonymous function, you can via call overloading: function (T::typeof(f))(t,u,du)
println(u)
println(du)
u,du
end so there's really no disadvantage to using an anonymous function in this case. Let me know if this helps. I'll keep this open for awhile if you have any more questions, though this is more of an issue with Julia itself. |
Thanks for the explanations! I thought that function redefinition in Julia worked as I expect them to, and it just prints warnings. I convinced myself that it was not a Julia issue because of the following:
The output is
as expected. So what's different between that and the ODE snippet I pasted? |
See my response here: https://www.reddit.com/r/Julia/comments/5i53ij/const_v_static/ I think it's because in this example, |
I see, so it is a Julia issue and not a DifferentialEquations.jl issue, sorry for the noise and thanks for the explanation! If anybody finds this thread and is as confused as I am, if I understand correctly, the official advice is "don't redefine functions", and the recommended workflow for the modify/test loop is to put everything inside modules, where function redefinition is allowed (because it's this case, it's the module that gets redefined, and inter-module inlining is not allowed, I guess?) I hope it'll get fixed and function redefinitions are allowed, though... |
Or you can use anonymous functions. They are just as performant and you can even add dispatches to them, as I showed above. They don't have function re-definition problems. |
Closing this because this isn't actionable, but it'll stay around in search for whoever else runs into this. |
Hi,
include() this file once, redefine f by commenting out the print(), include it again, the print() still gets called. What's going on here?
julia> versioninfo()
Julia Version 0.5.0
Commit 3c9d753 (2016-09-19 18:14 UTC)
DifferentialEquations.jl commit 0e86aab
The text was updated successfully, but these errors were encountered: