Closed ruricolist closed 7 years ago
Thanks, fixed. This kind of bug always bites me... Variables in dolist
are not lexically bound.
(let (acc)
(dolist (s '(a b))
(push (lambda () `(,s)) acc))
(dolist (fn acc)
(print (funcall fn))))
;; -> (NIL)
;; -> (NIL)
On SBCL this does not happen. Surprisingly, this is acutally implementation-dependent. http://clhs.lisp.se/Body/m_dolist.htm
It is implementation-dependent whether dolist establishes a new binding of var on each iteration or whether it establishes a binding for var once at the beginning and then assigns it on any subsequent iterations.
The bug is in the expansion, not the macro itself.