# Destructuring function definition?

**URL:** https://discourse.julialang.org/t/destructuring-function-definition/135824
**Category:** General Usage
**Tags:** question
**Created:** [February 25, 2026, 2:03am UTC](https://discourse.julialang.org/t/destructuring-function-definition/135824 "2026-02-25T02:03:15Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![WalterMadelim](https://avatars.discourse-cdn.com/v4/letter/w/3e96dc/32.png) [@WalterMadelim](https://discourse.julialang.org/u/WalterMadelim)
#### Post date: [February 25, 2026, 2:03am UTC](https://discourse.julialang.org/t/destructuring-function-definition/135824/1 "2026-02-25T02:03:15Z")

</div>

Can you help me understand

```julia-auto
julia> module A
           f() = g()
           g() = f()
       end
Main.A

julia> module B
           f(), g() = g(), f()
       end
ERROR: UndefVarError: `g` not defined in `Main.B`

```

?

---

<div class="post-metadata">

### Author: ![WalterMadelim](https://avatars.discourse-cdn.com/v4/letter/w/3e96dc/32.png) [@WalterMadelim](https://discourse.julialang.org/u/WalterMadelim)
#### Post date: [February 25, 2026, 2:07am UTC](https://discourse.julialang.org/t/destructuring-function-definition/135824/2 "2026-02-25T02:07:21Z")

</div>

Oh, I see. the line inside `B` is not function definition.

```julia-auto
julia> module C
           f() = rand()
       end
Main.C

julia> C.f()
0.24515636911767225

julia> C.f()
0.6758273362892651

julia> module D
           f(), g() = rand(), rand()
       end
Main.D

julia> D.f()
0.6869168702705465

julia> D.f()
0.6869168702705465

julia> D.f
f (generic function with 1 method)

```

---

<div class="post-metadata">

### Author: ![heliosdrm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heliosdrm/32/3851_2.png) [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)
#### Post date: [February 25, 2026, 10:49am UTC](https://discourse.julialang.org/t/destructuring-function-definition/135824/3 "2026-02-25T10:49:50Z")

</div>

The problem in the original post was not related to the line in `B` being or not a function definition, but to `g` (referred to in the right hand side of that line) having been defined in a module `A` that `B` cannot “see”. In your second example, on the other hand, the right hand side of the line in `D` refers to functions that are in `Main` (`rand`), so they can be seen.

By the way, what I didn’t expect is that defining a tuple of functions does not behave as when they are defined individually: the function calls in the “definition” are evaluated right away, so `rand` is not random anymore. This can be seen more clearly if those definitions are made outside a module, directly on `Main`:

```julia
julia> f() = rand()
f (generic function with 1 method)

julia> g(), h() = rand(), rand()
(0.7979213943713473, 0.6634292395166483)

```
