1

我遇到了一个非常奇怪的问题。我有一个名为“定理”的列表,其中只有一项。这是证据:

[]> theorems
(((ROSES ARE RED) ^ (~ (ROSES ARE RED))))
[]> (car theorems)
((ROSES ARE RED) ^ (~ (ROSES ARE RED)))

显然 ((ROSES ARE RED) ^ (~ (ROSES ARE RED))) 是“定理”列表的成员。但是当我测试它的成员资格时,它失败了:

[]> (member '((ROSES ARE RED) ^ (~ (ROSES ARE RED))) theorems)
NIL

但是,如果我明确地调用它,它会起作用:

[]> (member (car theorems) theorems)
(((ROSES ARE RED) ^ (~ (ROSES ARE RED))))

为什么会发生这种情况,我该如何解决?

4

1 回答 1

6

Common LispEQL用作默认的测试函数。EQL检查项目是否是相同的相同项目。您想测试项目是否具有相同的结构。所以你需要使用EQUALor EQUALP

CL-USER 11 > (setf theorems '(((ROSES ARE RED) ^ (~ (ROSES ARE RED)))))
(((ROSES ARE RED) ^ (~ (ROSES ARE RED))))

CL-USER 12 > (member '((ROSES ARE RED) ^ (~ (ROSES ARE RED))) theorems)
NIL

告诉MEMBER使用EQUAL

CL-USER 13 > (member '((ROSES ARE RED) ^ (~ (ROSES ARE RED)))
                     theorems
                     :test 'equal)
(((ROSES ARE RED) ^ (~ (ROSES ARE RED))))
于 2012-05-10T16:03:10.737 回答