beta = 0.5
WARNING: imported binding for beta overwritten in module Main
while if you comment out the for cycle, you always get the expected beta = 0.5.
Please note that the result shown above is only seen if the kerner runs for
the first time over the code.
Version 0.4.6 behaves, in contrast, as expected (we get 0.5).
I can also produce the same result in the following way:
julia> methods(beta)
# 4 methods for generic function "beta":
beta(x::Number, w::Number) at special/gamma.jl:492
beta{T1<:Number,T2<:Number}(x::T1, y::AbstractArray{T2,N<:Any}) at operators.jl:562
beta{T1<:Number,T2<:Number}(x::AbstractArray{T1,N<:Any}, y::T2) at operators.jl:563
beta{T1<:Number,T2<:Number}(x::AbstractArray{T1,N<:Any}, y::AbstractArray{T2,N<:Any}) at operators.jl:564
julia> beta = 0.5
WARNING: imported binding for beta overwritten in module Main
0.5
Not calling methods(beta) does not produce the warning.
I’m guessing the for statement triggers compilation of the entire code-block, whereas a block without a loop is compiled and executed line-by-line. So the situation is similar to:
function foo()
@eval Main beta = 0.5
print("Main.beta = ", Main.beta,"\n")
end
foo()
This will output the warning, followed by “Main.beta = beta”, which is expected and documented behavior, because changing beta does not trigger re-compilation of the function. The case of the REPL is different, though…
Defining a variable before it has been used in any way does not trigger a warning (or method extension error) because doing so would cause new exports from packages that clash with variable names in the code using the packages to break existing code.
julia> beta = 3
3
julia> workspace()
julia> beta
bbeta (generic function with 4 methods)
julia> beta = 3
WARNING: imported binding for beta overwritten in module Main
3
julia> workspace()
julia> beta(x::Int) = 3
beta (generic function with 1 method)
julia> workspace()
julia> beta
beta (generic function with 4 methods)
julia> beta(x::Int) = 3
ERROR: error in method definition: function Math.beta must be explicitly imported to be extended
I don’t think the point of the original post was to discuss the warning, but rather the fact that the assignment beta = 0.5 inside the if-statement at the REPL does not take effect immediately.
Thanks for the opinion.
I have expected the developers read this forum, too.
I will file an issue unless somebody turns up here soon to argue it is ok.