I've been working on a side project, but I'm back... In my search to close the holes in my cognition of Lisp, I came across this paper. The code:
Code: Select all
(defvar z 1) ;; binding persists unless mutated destructively
(defun koo() z) ;; returns the value binding of 'z
(defun laz()
(let ((z 2)) ;; value binding of 'z is within code of the 'let body form
(koo))) ;; 'koo is outside the code for 'laz
(laz) ;; returns (2) for the lexically scoped value binding of 'z.
Code: Select all
(defun maz()
(let ((z 2))
(list z (symbol-value 'z)))) ;; list the value binding of 'z and its symbol-value
(maz) ;; returns the list (2 2)
Code: Select all
(defun naz()
(let ((x 2)) ;; 'x has no binding, period.
(list x (symbol-value 'x)))) ;; 'symbol-value doesn't see lexical variables(?)
(naz) ;; when evaluated will return an error since 'x is a lexical variable: behavior is as expected. Yea!!!
(defun loo()
(let ((x 1))
(declare (special x)) ;; 'x is now a dynamic variable within the 'let body form
(naz))) ;; 'naz is called with the dynamic binding over 'x
(loo) ;; returns the list(2 1). 'symbol-value returns (1) for the value of 'x: again, behavior as expected