鑑於該實施例中的代碼(從Reddit /r/lisp question):即使未設置,SBCL也會更改本地綁定函數對象的EQness?
(defun next (pos)
(nth (1+ pos)
'(0 1 2 3 4 5 6 7 8 9 10)))
(defvar *next* (function next))
(let ((old-next #'next)
(previous (make-hash-table)))
(format t "~% 1 EQ? ~a" (eq old-next *next*))
(defun next (pos)
(or (gethash pos previous)
(setf (gethash pos previous) (funcall old-next pos))))
(format t "~% 2 EQ? ~a" (eq old-next *next*)))
上面建立功能NEXT
。在LET
內部,我們保留舊功能OLD-NEXT
。然後我們重新定義LET
內的全局函數NEXT
。
CCL/CMUCL/GCL/ECL/CLISP/LispWorks/ABCL:
? (load "test.lisp")
1 EQ? T
2 EQ? T
只有SBCL(SBCL 1.3.11)具有一個不同的結果:
* (load "test.lisp")
1 EQ? T
2 EQ? NIL
本地的值變量old-next
不再是eq
到全局變量*next*
的值。
爲什麼?
你也問過SBCL的郵件列表嗎? – coredump
@coredump:不,還沒有 –