Bag*_*ers 5 macros loops common-lisp
我扩展了下面的宏,看看它是如何工作的,发现自己有点困惑.
(loop for i below 4 collect i)
Run Code Online (Sandbox Code Playgroud)
扩展到(为了便于阅读,我已经清理了一点)
(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 "-------")
(go sb-loop::next-loop)
sb-loop::end-loop
(return-from nil (cdr list-head))))))
Run Code Online (Sandbox Code Playgroud)
..这里是运行上面的输出..
;; "-------"
;; (NIL 0)
;; (0)
;; "-------"
;; "-------"
;; (NIL 0 1)
;; (1)
;; "-------"
;; "-------"
;; (NIL 0 1 2)
;; (2)
;; "-------"
;; "-------"
;; (NIL 0 1 2 3)
;; (3)
;; "-------"
Run Code Online (Sandbox Code Playgroud)
我只是看不到列表头被修改的位置,我必须假设头部和尾部都是eq,因此修改一个正在修改另一个但是有人可以请分解rplacd线上发生的事情吗?