In a progamming language with
NestedScopes, source code has a nested structure such that variable definitions can be introduced at any level of nesting.
NestedScopes can be combined with either
LexicalScoping or
DynamicScoping; see the
DynamicScoping entry for an explanation of the differences.
Languages that support nested scopes include
SchemeLanguage,
CommonLisp,
EeLanguage, and
JavaLanguage (using
InnerClasses).
In
CeeLanguage, 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. SchemeLanguage only has one kind of scope for names, but procedure definitions may be nested arbitrarily deeply.
While it is not possible in AnsiCee 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,
GnuCee supports nested functions, and therefore full
NestedScopes.
See also
GlobalVariablesConsideredHarmful,
LexicalScoping,
DynamicScoping.