I expanded the macro below to see how it works, and got a little confused.
(loop for i below 4 collect i)
expands to (I cleaned it a bit for readability)
(block nil (let ((i 0)) (declare (type (and number real) i)) (let* ((list-head (list nil)) (list-tail list-head)) (tagbody sb-loop::next-loop (when (>= i 4) (go sb-loop::end-loop)) (rplacd list-tail (setq list-tail (list i))) (setq i (1+ i)) (print "-------") ;; added so I could see the lists grow (print list-head) (print list-tail) (print "
.. and here is the result of the work above.
;; "-------" ;; (NIL 0) ;; (0) ;; "-------" ;; "-------" ;; (NIL 0 1) ;; (1) ;; "-------" ;; "-------" ;; (NIL 0 1 2) ;; (2) ;; "-------" ;; "-------" ;; (NIL 0 1 2 3) ;; (3) ;; "-------"
I just donβt see where the list is changed, I have to assume that the head and tail are eq , and thus a modification of one of them has changed the other, but someone can break what is happening on the rplacd line
source share