# What are Opaque Closures?

**URL:** https://discourse.julialang.org/t/what-are-opaque-closures/60006
**Category:** General Usage
**Tags:** question
**Created:** [April 25, 2021, 9:45pm UTC](https://discourse.julialang.org/t/what-are-opaque-closures/60006 "2021-04-25T21:45:50Z")
**Posts on this page:** 1
**Showing post:** 1

<div class="post-metadata">

### Author: ![suavesito](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/suavesito/32/34386_2.png) [@suavesito](https://discourse.julialang.org/u/suavesito)
#### Post date: [April 25, 2021, 9:45pm UTC](https://discourse.julialang.org/t/what-are-opaque-closures/60006/1 "2021-04-25T21:45:50Z")

</div>

In Slack there was a [question](https://julialang.slack.com/archives/C67910KEH/p1619311934178800?thread_ts=1619276549.161100&cid=C67910KEH) about opaque closures. I found that what I was assuming they were is not the real thing, they are not closures that pass variables as value… so here I post the answer (thanks to @oxinabox) and a [link](https://julialang.slack.com/archives/C67910KEH/p1619342841192300?thread_ts=1619276549.161100&cid=C67910KEH) to the original comment so it can be more visible.

> As I understand it.  
> This is **not** true \[1\]. They do not do that.

> Opaque closures are closures that make no promises about what is inside them.

> Normal closures promise to carry references to every variable that is used inside them (and nothing else), and to run exactly the code inside them when they are called. Including respecting newly created or overwritten methods.

> Opaque closures on the other hand relax the requirements, and basically just promise to perform something equivalent in behaviour to their body. Except they always run in the world age they were created, so they don’t observe new methods that were added (this makes them very unfriendly for interactive use, but like @pure they are not really intended for normal use).  
> What this allows them to do is move computation that depends only on variables in the parent scope (and not on the closures inputs) out of the closure and into the parent scope so they run when the closure is created (and then that result is closed over). This in turn makes them much more optimizable as the optimizer can optimize the (parts of) the closure body and the parent function together.

> **This has nothing to do with capture by name or capture by value.**

* * *

1. That they pass variables as value.

---

_[View the full topic](https://discourse.julialang.org/t/what-are-opaque-closures/60006)._
