;; GCL is lexically scoped by default, but allows you to create ;; "special" dynamically bound variables (typically used for ;; configuration variables that must affect all relevant ;; computations depending on their current value at all times, ;; i.e., always looked up by name when referenced). $ gcl GCL (GNU Common Lisp) 2.6.12 ANSI Nov 27 2014 05:23:43 Source License: LGPL(gcl,gmp), GPL(unexec,bfd,xgcl) Binary License: GPL due to GPL'ed components: (READLINE UNEXEC) Modifications of this banner must retain notice of a compatible license Dedicated to the memory of W. Schelter Use (help) to get some basic information on how to use GCL. Temporary directory for compiler files set to /private/var/folders/1h/3prjrhy96y55j8jrvttgd_kw0000gp/T/ ;; Here's what a function normally does: it closes over a lexically scoped variable: >(defun foo () (let ((x 1)) (lambda (y) (+ x y)))) FOO ;; note the closure saving the value of X: >(setq bar (foo)) (LAMBDA-CLOSURE ((X 1)) () ((FOO BLOCK #<@0000000103C35780>)) (Y) (+ X Y)) >(funcall bar 100) 101 ;; the global X has nothing to do with the closed-over local X in BAR: >(setq x 1000) 1000 >(funcall bar 100) 101 ;; But if you declare a variable to be "special", things will change: >(defvar z) Z ;; re-running the same definition now yields different results: not closed over Z! >(defun foo () (let ((z 1)) (lambda (y) (+ z y)))) FOO >(setq bar (foo)) (LAMBDA-CLOSURE () () ((FOO BLOCK #<@000000010396A130>)) (Y) (+ Z Y)) ;; Z's local value was not closed over, and instead gets looked up at invocation time. ;; It causes an error when there is no binding for Z: >(funcall bar 100) Error: Fast links are on: do (si::use-fast-links nil) for debugging Signalled by LAMBDA-CLOSURE. Condition in LAMBDA-CLOSURE [or a callee]: INTERNAL-SIMPLE-UNBOUND-VARIABLE: Cell error on Z: Unbound variable: Broken at +. Type :H for Help. 1 Return to top level. >>1 Top level. ;; ...and it will pick up whatever binding for Z exists at the time of evaluation, ;; in contrast to the above example with X and the closure over it: >(setq z 1000) 1000 >(funcall bar 100) 1100 >(setq z 2000) 2000 >(funcall bar 100) 2100 >(setq z 3000) 3000 >(funcall bar 100) 3100