For those arriving on this thread in 2026, this discussion doesn’t apply to recent Julia versions. Here it is in Julia 1.13:
const x1=0;
julia> function f1()
global x1+=1
i->i+x1
end
f1 (generic function with 1 method)
julia> f1()(0)
ERROR: invalid assignment to constant Main.x1. This redefinition may be permitted using the `const` keyword.
Stacktrace:
[1] f1()
@ Main ./REPL[5]:2
[2] top-level scope
@ REPL[7]:1
So const x1 cannot be changed from inside f1
However, redefinition of x1 in REPL using the const keyword is fine and doesn’t yield a warning. I suppose this is the feature introduced in 1.12, as per 1.12 release notes:
- Redefinition of constants is now well defined and follows world age semantics (#57253). Additional redefinitions (e.g. of types) are now allowed. See the new manual chapter on world age.