In computer science, a lexically scoped (or statically scoped) programming language is one in which the free variables in a procedure are evaluated in the environment at the procedure definition. For example:
let a = 5
in let p = proc () a
       a = 10
   in (p)
will return 5 in an interpreter with lexical scoping, since the variable a is bound to the value 5 when p is defined.

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.