我想使用Common Lisp CLOS对象作为哈希表中的键。我以为就这么简单:
(defclass my-class () ((a :accessor a :initarg a)))
(defun my-class= (my-instance-1 my-instance-2)
(equal (a my-instance-1) (a my-instance-2)))
(defparameter my-hash-table (make-hash-table :test #'my-class=))
检查Common Lisp Hyperspec,看来我只能使用eq,eql,equal或equip来测试相等性。
有什么办法可以做到吗?还是这只是一件愚蠢的事情,这就是为什么标准不允许这样做的原因?
最佳答案
通用Lisp标准不提供任何机制来提供其他测试功能(超越标准)。您有2个选择:
sb-ext:define-hash-table-test
函数(documentation)ext:define-hash-table-test
(documentation):test
参数的非标准值,并具有:hash-function
参数(Allegro,Lispworks)。 关于key - 使用Common Lisp CLOS对象作为哈希表中的键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6605077/