Dynamic Scope refers to the scope of variables in a programming language. When a language is dynamically scoped, variable references will always refer to the variable that is "closest" to it on the stack. For example, in Emacs Lisp:

(defvar x 5)
(defun +x (y)
  (+ x y))
(+x 5) ; evaluates to 10
(let ((x 10))
  (+x 5)) ; evaluates to 15

DynamicScope is generally considered to be confusing because the value of any free variable can change in value between runs of the function. It is also more difficult for a compiler to optimize functions in a dynamically scoped language than it is for a statically scoped (StaticScope) language. Most languages in use today have StaticScope.

The original implementation of LispLanguage was dynamically scoped. EmacsLispLanguage is an example of a dynamically scoped language that is still in use today.

DynamicScope (last edited 2008-07-09 05:47:55 by localhost)