# What are the functions defined inside other functions called?

**URL:** <https://discourse.julialang.org/t/what-are-the-functions-defined-inside-other-functions-called/42915>\
**Category:** General Usage\
**Created:** [July 12, 2020, 2:43am UTC](https://discourse.julialang.org/t/what-are-the-functions-defined-inside-other-functions-called/42915 "2020-07-12T02:43:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [July 12, 2020, 2:43am UTC](https://discourse.julialang.org/t/what-are-the-functions-defined-inside-other-functions-called/42915/1 "2020-07-12T02:43:40Z")

</div>

I’ve been looking for “nested” or “inner” or “subfunction” in the manual: no hits.  
Does anyone remember?

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [July 12, 2020, 2:45am UTC](https://discourse.julialang.org/t/what-are-the-functions-defined-inside-other-functions-called/42915/2 "2020-07-12T02:45:40Z")

</div>

Closures is a typical name. I’m not sure if Julia has a specific one.

---

<div class="post-metadata">

**Author:** ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)\
**Post date:** [July 12, 2020, 2:47am UTC](https://discourse.julialang.org/t/what-are-the-functions-defined-inside-other-functions-called/42915/3 "2020-07-12T02:47:50Z")

</div>

Closure typically has a slightly different / more broad meaning than that, but it’s tightly related.

I’d just call it an ‘inner function’ if I don’t care if the function closes over any values or not.

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [July 12, 2020, 2:51am UTC](https://discourse.julialang.org/t/what-are-the-functions-defined-inside-other-functions-called/42915/4 "2020-07-12T02:51:52Z")

</div>

“What are the functions defined inside other functions called?”

Confusing?

---

<div class="post-metadata">

**Author:** ![dlakelan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlakelan/32/8491_2.png) [@dlakelan](https://discourse.julialang.org/u/dlakelan)\
**Post date:** [July 12, 2020, 5:43am UTC](https://discourse.julialang.org/t/what-are-the-functions-defined-inside-other-functions-called/42915/5 "2020-07-12T05:43:07Z")

</div>

Just call them functions 😉

closure specifically is when the function has free variables whose values come from the lexical scope.

---

<div class="post-metadata">

**Author:** ![longemen3000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/longemen3000/32/7298_2.png) [@longemen3000](https://discourse.julialang.org/u/longemen3000)\
**Post date:** [July 12, 2020, 5:49am UTC](https://discourse.julialang.org/t/what-are-the-functions-defined-inside-other-functions-called/42915/6 "2020-07-12T05:49:45Z")

</div>

if the inner function cannot be defined outside of the outer function, is a closure over the variables in the outer function:

```julia
function outer(x)
   a = x+1
  inner(y) = a + y #requires information only available at this scope, its a closure
  return inner(2)
end

```

but a closure is a function too

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [July 12, 2020, 1:40pm UTC](https://discourse.julialang.org/t/what-are-the-functions-defined-inside-other-functions-called/42915/7 "2020-07-12T13:40:41Z")

</div>

I did find “inner functions” mentioned in the PDF version of the manual (the  
search in the online version is a bit hard to use). Not really defined, passing references, but the text was quite consistent in calling it inner, so inner it is.

Thanks to all who responded.
