I understand how this code works:
(defvar *nums* '(2 3 5))
(defun print-nums ()
(format t "~a~%" *nums*))
(print-nums)
-> (2 3 5)
-> NIL
I even understand how the new value of the dynamically bound variable *nums*
is passed on to print-nums
in this code:
(let ((*nums* '(1 2 3)))
(print-nums))
-> (1 2 3)
-> NIL
But why doesn't the code below work the same way?
(defvar *my-nums-f* (let ((*nums* '(1 2 3)))
#'(lambda () (format t "~a~%" *nums*))))
(funcall *my-nums-f*)
-> (2 3 5)
-> NIL
Does the concept of a closure not apply to dynamically bound variables, or am I doing something wrong? If I have wrongly understood the concept of a closure, could someone please explain it to me?