Nested Scopes

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:

  1. global
  2. translation unit
  3. static (within a function)
  4. 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.


EditText of this page (last edited December 2, 2005) or FindPage with title or text search