Scope (programming)

related topics
{math, number, function}
{group, member, jewish}
{system, computer, user}
{style, bgcolor, rowspan}

In computer programming, scope is an enclosing context where values and expressions are associated. Various programming languages have various types of scopes. The type of scope determines what kind of entities it can contain and how it affects them—or semantics. Typically, scope is used to define the extent of information hiding—that is, the visibility or accessibility of variables from different parts of the program. Scopes can:

A namespace is a scope that uses the enclosing nature of the scope to group logically related identifiers under a single identifier. Thus, scopes can affect the name resolution for their contents.

Variables are associated with scopes. Different scoping types affect how local variables are bound. This has different consequences depending if the language has static (lexical) or dynamic scoping.

Contents

History

Lexical scoping was used for ALGOL and has been picked up in most other languages since then. Static (lexical) scoping was also introduced in LISP 1.5 (via the Funarg device developed by Steve Russell, working under John McCarthy). The original Lisp interpreter (1960) and most early Lisps used dynamic scoping, but descendants of dynamically scoped languages often adopt static scoping; Common Lisp has both dynamic and static scoping while Scheme uses static scoping exclusively. Perl is another language with dynamic scoping that added static scoping afterwards. Languages like Pascal and C have always had lexical scoping, since they are both influenced by the ideas that went into ALGOL 60 (although C did not include lexically nested functions).

Full article ▸

related documents
Tychonoff's theorem
Homological algebra
Semigroup
Ordinary differential equation
Key size
Normed vector space
Modular arithmetic
Filter (mathematics)
XPath 1.0
Holomorphic function
Countable set
Exclusive or
J (programming language)
Complex analysis
Power series
Natural logarithm
Gödel's completeness theorem
Ultrafilter
Partition (number theory)
Abel–Ruffini theorem
Absolute convergence
Objective Caml
Galois theory
Ideal (ring theory)
Elementary algebra
Miranda (programming language)
Natural transformation
Gaussian quadrature
Sequence
Elliptic curve