πDynamic scoping
As opposed to lexical scoping, dynamic scoping traverses the current invocation stack to find free variables. (Lexical scoping traverses scopes defined by lexical structure of the program.)
Examples
Emacs Lisp uses dynamic scoping for all variables by default.
(defvar name "world") (defun hello () (princ (format "Hello, %s!\n" name))) (let ((name "blah")) ; name is a local binding here (hello)) (hello)
Hello, blah! Hello, world!
See also
Backlinks
- π Co-effects
- π Dependency injection
- π Racket: Parameters
- π Reader/State vs dynamic scoping
- π Is effect system only relevant to typed languages?
- π Β§ Effect system
- π Scope vs. Extent
- π In Common Lisp, all global variables are automatically βspecialβ (use dynamic scoping)
- π Dynamic scoping is a better model for global variables
- π Dynamic scoping works badly with laziness
- π Clojure: dynamic scoping
- π Β§ Programming Language