# Redefining constants in functions, confusing behavior

**URL:** <https://discourse.julialang.org/t/redefining-constants-in-functions-confusing-behavior/27538>\
**Category:** General Usage\
**Tags:** question\
**Created:** [August 14, 2019, 2:42pm UTC](https://discourse.julialang.org/t/redefining-constants-in-functions-confusing-behavior/27538 "2019-08-14T14:42:56Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![pierre-haessig](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pierre-haessig/32/217129_2.png) [@pierre-haessig](https://discourse.julialang.org/u/pierre-haessig)\
**Post date:** [October 31, 2026, 3:27pm UTC](https://discourse.julialang.org/t/redefining-constants-in-functions-confusing-behavior/27538/5 "2026-10-31T15:27:33Z")

</div>

For those arriving on this thread in 2026, this discussion doesn’t apply to recent Julia versions. Here it is in Julia 1.13:

```julia-repl
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](https://docs.julialang.org/en/v1.12-dev/NEWS/):

> - Redefinition of constants is now well defined and follows world age semantics ([#57253](https://github.com/JuliaLang/julia/issues/57253)). Additional redefinitions (e.g. of types) are now allowed. See [the new manual chapter on world age](https://docs.julialang.org/en/v1/manual/worldage/).

---

_[View the full topic](https://discourse.julialang.org/t/redefining-constants-in-functions-confusing-behavior/27538)._
