# \[Documentation Incomplete Explanation?\] Methods Chapter - Redefining Methods

**URL:** <https://discourse.julialang.org/t/documentation-incomplete-explanation-methods-chapter-redefining-methods/135695>\
**Category:** New to Julia\
**Tags:** question, documentation, methods\
**Created:** [February 16, 2026, 10:52pm UTC](https://discourse.julialang.org/t/documentation-incomplete-explanation-methods-chapter-redefining-methods/135695 "2026-02-16T22:52:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![fincleah](https://avatars.discourse-cdn.com/v4/letter/f/a183cd/32.png) [@fincleah](https://discourse.julialang.org/u/fincleah)\
**Post date:** [February 16, 2026, 10:52pm UTC](https://discourse.julialang.org/t/documentation-incomplete-explanation-methods-chapter-redefining-methods/135695/1 "2026-02-16T22:52:46Z")

</div>

Hi - I’m currently reading the manual to learn Julia.

I’ve spotted maybe an incomplete example in the Methods chapter on redefining methods.

It seems to say that there are two definitions of the `newfun()` function, but I can only spot what must be the “new” definition within the `tryeval()` function body.

Could someone maybe confirm this or explain why I might be wrong/misunderstanding?

Many thanks,  
Jaimin

 ![Screenshot_20260216_224222_1](https://global.discourse-cdn.com/julialang/original/3X/4/9/4970af8f8a734b26d05efc0fcbb297012e2d6163.jpeg)

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [February 16, 2026, 11:00pm UTC](https://discourse.julialang.org/t/documentation-incomplete-explanation-methods-chapter-redefining-methods/135695/2 "2026-02-16T23:00:41Z")

</div>

The definition of `newfun` is not a closure inside `tryeval`, it’s evaluated into the global scope. That’s true for all `@eval` code. The old (or nonexistent) versus new definitions are split across different world ages. You could study world age in that section and the linked page, but in practice, you’ll want to stick to closures or wait until function calls like `tryeval()` return all the way to the global scope before calling any of the methods.

---

<div class="post-metadata">

**Author:** ![fincleah](https://avatars.discourse-cdn.com/v4/letter/f/a183cd/32.png) [@fincleah](https://discourse.julialang.org/u/fincleah)\
**Post date:** [February 17, 2026, 11:00am UTC](https://discourse.julialang.org/t/documentation-incomplete-explanation-methods-chapter-redefining-methods/135695/3 "2026-02-17T11:00:42Z")

</div>

Hi Benny,

Many thanks for your reply. Given what you’ve said, I’ve read The World Age mechanism documentation page (though it seems the link at the bottom of the screenshot (in the “Redefining Methods” section) is not pointing to the right webpage…), and I think I understand.

I trialled a few things in the REPL, and want to run a few things by you if possible. First, here’s what I tested:

```julia-auto

julia> function tryeval()
           newfun() = 1
           return newfun()
       end
tryeval (generic function with 1 method)

julia> tryeval()
1

julia> newfun()
ERROR: UndefVarError: `newfun` not defined in `Main`
Suggestion: check for spelling errors or missing imports.
Stacktrace:
 [1] top-level scope
   @ REPL[5]:1

julia> function tryeval2()
           @eval newfun2() = 1
           return newfun2()
       end
tryeval2 (generic function with 1 method)

julia> tryeval2()
WARNING: Detected access to binding `Main.newfun2` in a world prior to its definition world.
  Julia 1.12 has introduced more strict world age semantics for global bindings.
  !!! This code may malfunction under Revise.
  !!! This code will error in future versions of Julia.
Hint: Add an appropriate `invokelatest` around the access to this binding.
To make this warning an error, and hence obtain a stack trace, use `julia --depwarn=error`.
ERROR: MethodError: no method matching newfun2()
The applicable method may be too new: running in world age 38703, while current world is 38705.

Closest candidates are:
  newfun2() (method too new to be called from this world context.)
   @ Main REPL[6]:2

Stacktrace:
 [1] tryeval2()
   @ Main ./REPL[6]:3
 [2] top-level scope
   @ REPL[7]:1

julia> newfun2()
1

```

Therefore:

1. If `tryeval()` above is run, there is no problem, because `newfun()` is just a new function/method defined in the local scope of `tryeval()`. Because of this, it is defined within the same world age as in the definition of `tryeval()` - and so when `tryeval()` is called, the evaluation of `newfun()` is within the same world age?
2. since the `@eval` macro evaluated things in a global scope (?) as you say, the definition/evaluation of `newfun2()` occurs in the global (newest) world age, yet the definition of `tryeval2()` occurs within a previous world age. Therefore, only because of the special behaviour of `@eval`, this issue occurs?

I also found this example in the world age mechanism section:

```julia-auto
julia> function f end
f (generic function with 0 methods)

julia> begin
           @show (Int(Base.get_world_counter()), Int(Base.tls_world_age()))
           Core.eval(@ __MODULE__ , :(f() = 1))
           @show (Int(Base.get_world_counter()), Int(Base.tls_world_age()))
           f()
       end
(Int(Base.get_world_counter()), Int(Base.tls_world_age())) = (38452, 38452)
(Int(Base.get_world_counter()), Int(Base.tls_world_age())) = (38453, 38452)
ERROR: MethodError: no method matching f()
The applicable method may be too new: running in current world age 38452, while global world is 38453.

Closest candidates are:
  f() (method too new to be called from this world context.)
   @ Main REPL[2]:3

Stacktrace:
 [1] top-level scope
   @ REPL[2]:5

julia> (f(), Int(Base.tls_world_age()))
(1, 38453)

```

1. Correct me if I’m wrong, but is this example in essence the same as in the “Redefining Methods” section (just with a slightly different @eval calling)? If so, I find it very helpful to actually have a visible empty definition of the function in question ("`function f end `"). I feel like this could be a lot clearer in the redefining methods section.
2. Final Question, is a closure just a function that references variables outside the hard local scope of that function? Is this the only difference between a standard “function” and a “closure”?

Your help is greatly appreciated.

Many thanks,  
Jaimin

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [February 17, 2026, 11:48am UTC](https://discourse.julialang.org/t/documentation-incomplete-explanation-methods-chapter-redefining-methods/135695/4 "2026-02-17T11:48:45Z")

</div>

1. Yes, but also note that running `tryeval` does not create new worlds (because `newfun` is local, as you said).
2. Defining a new method causes a world age increment, but `tryeval2` _runs_ in a fixed world. You can work around that with e.g. `invokelatest` or `Base.invoke_in_world`, although that is not recommended for non-interactive uses. `@eval` isn’t really what causes the issue, it’s just a convenient way to create methods in newer worlds (and also a common anti-pattern)
3. Yup.
4. Technically yes, but “closure” is most often used for _local_ functions referencing variables in an outer _local_ scope. The main point @Benny was trying to make, I believe, is that local function definitions in your method body are much preferred over trying to modify global state.

---

<div class="post-metadata">

**Author:** ![fincleah](https://avatars.discourse-cdn.com/v4/letter/f/a183cd/32.png) [@fincleah](https://discourse.julialang.org/u/fincleah)\
**Post date:** [February 20, 2026, 11:04am UTC](https://discourse.julialang.org/t/documentation-incomplete-explanation-methods-chapter-redefining-methods/135695/5 "2026-02-20T11:04:06Z")

</div>

I see - thank you very much for answering my questions. I believe I understand it now.

Wishing you all the best!!
