Content deleted Content added
No edit summary Tag: Reverted |
EnIRtpf09b (talk | contribs) m Reverted edits by 192.140.149.241 (talk) (AV) |
||
Line 3:
{{Distinguish|text=the programming language [[Clojure]]}}
{{Use dmy dates|date=August 2020}}
In
== History and etymology ==
Line 74:
== Applications ==
The use of closures is associated with languages where functions are [[first-class object]]s,
[[Julia (programming language)|Julia]],
[[Python (programming
[[Rust (programming language)|Rust]].
Closures are also frequently used with [[Callback (computer programming)|callback]]s, particularly for [[event handler]]s, such as in [[JavaScript]], where they are used for interactions with a [[dynamic web page]].
Closures can also be used in a [[continuation-passing style]] to [[information hiding|hide state]]. Constructs such as [[object (computer science)|object]]s and [[control structure]]s can thus be implemented with closures. In some languages, a closure may occur when a function is defined within another function, and the inner function refers to local variables of the outer function. At [[Run time (program lifecycle phase)|run-time]], when the outer function executes, a closure is formed, consisting of the inner function's code and references (the upvalues) to any variables of the outer function required by the closure.
=== First-class functions ===
{{further|First-class function}}
Line 94:
</syntaxhighlight>
In this example, the [[Lambda (programming)|
The closure is then passed to the <code>filter</code> function, which calls it repeatedly to determine which books are to be added to the result list and which are to be discarded. Because the closure itself has a reference to <code>threshold</code>, it can use that variable each time <code>filter</code> calls it. The function <code>filter</code> itself might be defined in a completely separate file.
|