Nested Scopes

In a progamming language with Nested Scopes, source code has a nested structure such that variable definitions can be introduced at any level of nesting.

Nested Scopes can be combined with either Lexical Scoping or Dynamic Scoping; see the Dynamic Scoping entry for an explanation of the differences.

Languages that support nested scopes include Scheme Language, Common Lisp, Ee Language, and Java Language (using Inner Classes).


In Cee Language, there are four kinds of scope:

global

translation unit

static (within a function)

automatic

The list of C "scopes" above seems to conflate scoping, visibility, linkage rules and lifetime (which is no surprise). Note also that kinds of scope does not map well to levels of scoping. Scheme Language only has one kind of scope for names, but procedure definitions may be nested arbitrarily deeply.

While it is not possible in Ansi Cee to nest the definition of functions, it is possible to nest scopes where variables are defined arbitrarily deeply, like this:

void wibble(){ { int a; { int b; { //etc... } } } }

As an extension, Gnu Cee supports nested functions, and therefore full Nested Scopes.


See original on c2.com