Hello all,
I know that redefining constants is discouraged and is only allowed as a convenience. However, I found this confusing:
julia> const x1=0;const x2=0;
julia> function f1()
global x1+=1
i->i+x1
end
f1 (generic function with 1 method)
julia> function f2()
i->(global x2+=1;i+x2)
end
f2 (generic function with 1 method)
julia> f1()(0),f2()(0)
WARNING: redefining constant x1
WARNING: redefining constant x2
(1, 0)
julia> const x1=0;const x2=0;
julia> function f1()
global x1+=1
i->i+x1
end
f1 (generic function with 1 method)
julia> function f2()
i->(global x2+=1;i+x2)
end
f2 (generic function with 1 method)
julia> f1()(0),f2()(0)
WARNING: redefining constant x1
WARNING: redefining constant x2
(1, 0)
julia> x1,x2
(1, 1)
Can someone please help me understand why the behavior of the two functions is different, or whether/why it is expected.
Cheers!