Difference between revisions of "Closure (computer programming)"

From Wiki @ Karl Jones dot com
Jump to: navigation, search
(etc)
(Free variables and bound variables)
Line 1: Line 1:
 
In [[Programming language|programming languages]], a '''closure''' (also '''lexical closure''' or '''function closure''') is a technique for implementing [[Scope (computer science)|lexically scoped]] [[name binding]] in languages with [[First-class function|first-class functions]].
 
In [[Programming language|programming languages]], a '''closure''' (also '''lexical closure''' or '''function closure''') is a technique for implementing [[Scope (computer science)|lexically scoped]] [[name binding]] in languages with [[First-class function|first-class functions]].
  
Operationally, a closure is a data structure storing a function[a] together with an environment:
+
== Description ==
  
* A mapping associating each free variable of the function (variables that are used locally, but defined in an enclosing scope)
+
Operationally, a closure is a [[data structure]] storing a ''function'' (see [[Subroutine]]) together with an [[environment]]:
 +
 
 +
* A [[mapping]] associating each [[Free variables and bound variables|free variable]] of the function (variables that are used locally, but defined in an enclosing scope)
  
 
* With the value or storage location the name was bound to at the time the closure was created.
 
* With the value or storage location the name was bound to at the time the closure was created.
Line 11: Line 13:
 
== See also ==
 
== See also ==
  
 +
* [[Free variables and bound variables]]
 
* [[Google Closure Tools]]
 
* [[Google Closure Tools]]
  

Revision as of 05:14, 31 August 2015

In programming languages, a closure (also lexical closure or function closure) is a technique for implementing lexically scoped name binding in languages with first-class functions.

Description

Operationally, a closure is a data structure storing a function (see Subroutine) together with an environment:

  • A mapping associating each free variable of the function (variables that are used locally, but defined in an enclosing scope)
  • With the value or storage location the name was bound to at the time the closure was created.

A closure -- unlike a plain function -- allows the function to access those captured variables through the closure's reference to them, even when the function is invoked outside their scope.

See also

External links

The term closure has many different uses in different fields. See: