See https://github.com/JuliaLang/julia/issues/16965
On Thu, 2016-06-16 at 16:38, Jeffrey Sarnoff <jeffrey.sarn...@gmail.com> wrote: > that is not right, please enter it as an issue > https://github.com/JuliaLang/julia/issues > > (include your minimal example as > ```julia > <example that fails> > ``` > and the commit id) > > On Thursday, June 16, 2016 at 10:11:23 AM UTC-4, Chris Rackauckas wrote: >> >> It fails when you put it in a function: >> >> function g(a) >> if a >> f() = 2 >> else >> f() = 3 >> end >> return f >> end >> f = g(true) >> f() # Returns 3 >> >> Even more interestingly, g(false) in another REPL session gives an error: >> "f not defined". So in this setup you either get the second function (if >> you ask for the first one), or you get nothing! This is on Commit 59d1539 >> (4 days old master). >> >> On Thursday, June 16, 2016 at 1:34:34 AM UTC-7, Mauro wrote: >>> >>> On Thu, 2016-06-16 at 07:32, Chris Rackauckas <rack...@gmail.com> wrote: >>> > There seems to be an interesting change between v0.4.5 and v0.5. Take a >>> > look at the following code: >>> > >>> > if largeFluctuations >>> > function σ(y,t) >>> > dσ = zeros(19) >>> > dσ[1] = noiseLevel*1.5y[1] >>> > dσ[18]= noiseLevel*6y[18] >>> > return(dσ) >>> > end >>> > else >>> > function σ(y,t) >>> > dσ = zeros(19) >>> > dσ[1] = 0.02y[1] >>> > dσ[16]= 0.02y[16] >>> > dσ[18]= 0.2y[18] >>> > dσ[17]= 0.02y[17] >>> > return(dσ) >>> > end >>> > end >>> > >>> > In v0.4.5, this would work as expected: if largeFluctuations was set to >>> > true, then you would get the first function and if false the second. In >>> > v0.5, I tracked down to this error where it will always define sigma as >>> the >>> > second function. >>> > >>> > Is this change intentional? If so, why? >>> >>> Sounds like a bug to me. However this works as expected: >>> >>> julia> a = false >>> false >>> >>> julia> if a >>> f() = 2 >>> else >>> f() = 3 >>> end >>> f (generic function with 1 method) >>> >>> julia> f() >>> 3 >>> >>> new session: >>> >>> julia> a = true >>> true >>> >>> julia> if a >>> f() = 2 >>> else >>> f() = 3 >>> end >>> f (generic function with 1 method) >>> >>> julia> f() >>> 2 >>> >>> Maybe you can try to reduce your example further? >>> >>> > Is the proper way to do this in v0.5 using anonymous functions? I know >>> > there was a change to faster anonymous functions, but is it as fast as >>> > regular function, or are there some notable differences? >>> >>> Anonymous and normal functions are based on the same machinery in 0.5 >>> (e.g. anonymous functions can have methods now too). Both have the same >>> performance, also when used inside higher order functions. >>> >>