In computer science
, a lexically scoped (or statically scoped) programming language
is one in which the free variable
s in a procedure
are evaluated in the environment
at the procedure definition. For example:
let a = 5
in let p = proc () a
a = 10
will return 5 in an interpreter with lexical scoping, since the variable
is bound to the value 5 when
Lexical scoping is slightly more difficult to implement than dynamic scoping, but it makes programs much easier to understand. Almost all modern programming languages are lexically scoped.
Compare dynamic scoping.