www.delorie.com/gnu/docs/elisp-manual-21/elisp_147.html   search  
 
Buy the book!


GNU Emacs Lisp Reference Manual

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

11.9 Scoping Rules for Variable Bindings

A given symbol foo can have several local variable bindings, established at different places in the Lisp program, as well as a global binding. The most recently established binding takes precedence over the others.

Local bindings in Emacs Lisp have indefinite scope and dynamic extent. Scope refers to where textually in the source code the binding can be accessed. "Indefinite scope" means that any part of the program can potentially access the variable binding. Extent refers to when, as the program is executing, the binding exists. "Dynamic extent" means that the binding lasts as long as the activation of the construct that established it.

The combination of dynamic extent and indefinite scope is called dynamic scoping. By contrast, most programming languages use lexical scoping, in which references to a local variable must be located textually within the function or block that binds the variable.

Common Lisp note: Variables declared "special" in Common Lisp are dynamically scoped, like all variables in Emacs Lisp.

11.9.1 Scope  Scope means where in the program a value is visible. Comparison with other languages.
11.9.2 Extent  Extent means how long in time a value exists.
11.9.3 Implementation of Dynamic Scoping  Two ways to implement dynamic scoping.
11.9.4 Proper Use of Dynamic Scoping  How to use dynamic scoping carefully and avoid problems.


  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003