In
computer science, a dynamically scoped
programming language is one in which the
free variables in a
procedure are evaluated in the
environment at the point of call. For example:
let a = 5
in let p = proc () a
a = 10
in (p)
will return 10 in an interpreter with dynamic scoping, since the variable a is bound to the value 10 when p is called.
Dynamically scoped programs can be extremely difficult to understand. For example, the code fragments
let a = 3
p = proc () a
in let f = proc (x) (p)
a = 5
in (f 2)
and
let a = 3
p = proc () a
in let f = proc (a) (p)
a = 5
in (f 2)
will returns diffent values. (The preceding example was cribbed from
Essentials of Programming Languages by Friedman, Wand, and Haynes)
Compare lexical scoping.