# Is it possible to know if a function has captured local variables?

**URL:** <https://discourse.julialang.org/t/is-it-possible-to-know-if-a-function-has-captured-local-variables/128934>\
**Category:** General Usage\
**Tags:** function\
**Created:** [May 12, 2025, 9:18pm UTC](https://discourse.julialang.org/t/is-it-possible-to-know-if-a-function-has-captured-local-variables/128934 "2025-05-12T21:18:49Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![frankwswang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/frankwswang/32/18561_2.png) [@frankwswang](https://discourse.julialang.org/u/frankwswang)\
**Post date:** [May 12, 2025, 11:31pm UTC](https://discourse.julialang.org/t/is-it-possible-to-know-if-a-function-has-captured-local-variables/128934/8 "2025-05-12T23:31:32Z")

</div>

Okay, it seems that it’s not about whether the constructed function is a closure, but about how the global variable is embedded in the function body, which is even more confusing now:

```julia
julia> d = fill(1)
0-dimensional Array{Int64, 0}:
1

julia> function f3()
           function (y)
           d[] + y
           end
       end
f3 (generic function with 1 method)

julia> f3c = f3()
#3 (generic function with 1 method)

julia> f3c(1)
2

julia> d[] += 1
2

julia> f3c(1)
3

julia> f3c_dc = deepcopy(f3c)
#3 (generic function with 1 method)

julia> f3c_dc(1)
3

julia> d[] += 1
3

julia> f3c_dc(1)
4

julia> f3c(1)
4

```

---

_[View the full topic](https://discourse.julialang.org/t/is-it-possible-to-know-if-a-function-has-captured-local-variables/128934)._
