6.2 Preliminaries

6.2.1 What Is a Closure?

An understanding of lexical closures is fundamental not only to this chapter, but more broadly to the study of programming languages. A closure is a function that remembers the lexical environment in which it was created. A closure can be thought of as a pair of pointers: one to a block of code (defining the function) and one to an environment (in which function was created). The bindings in the environment are used to evaluate the expressions in the code. Thus, a closure encapsulates data and operations and thus, bears a resemblance to an object as used in object-oriented programming. Closures are powerful constructs in functional programming (as we see throughout this text), and an essential element in the study of binding and scope.

6.2.2 Static Vis-à-Vis Dynamic Properties

In the context of programming languages, the adjective static placed before a noun phrase describing a binding, concept, or property of a programming language or program indicates that the binding to which the noun phrase refers takes place before run-time; the adjective dynamic indicates that the binding takes place at runtime (Table 6.1). For instance, the binding of a variable to a data type (e.g., i n t a, semicolon.) takes place before run-time—typically at compile-time. In contrast, the binding of a variable to a value takes place at run-time—typically when an assignment statement (e.g., a equals 1, semicolon.) is executed.

Table 6.1 Static Vis-à-Vis Dynamic Bindings

A table on static and dynamic bindings.
Description
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.142.166