IT lexicon › Programming › Dynamic scoping

Dynamic scoping

Programming På svenska → Updated: 2026-11-12

Variable-lookup model in which a name is resolved by following the *call stack*, not the source code's textual structure.

In dynamic scoping, variable values are fetched from the most recent binding on the call stack, which can make code hard to reason about—the same variable can refer to different values depending on the calling context. Many early Lisp dialects used dynamic scoping by default, leading to surprising behavior when functions were called from unexpected contexts. From the mid-1970s onward, languages favored lexical scoping, which is more predictable. Some modern languages like Lisp offer dynamic scoping as an opt-in feature for special variables.

← Back to the lexicon