Common lisp 条件返回(nil)为true

Common lisp 条件返回(nil)为true,common-lisp,Common Lisp,几天前我开始学习common lisp,所以请记住我是个十足的noob,以下是我的代码: ELISP> (member nil '(2 3 nil)) (nil) ELISP> (if (member nil '(2 3 nil)) 'true 'false) true 所以我的问题是“如果”如何返回true?这种行为是正确的(NIL)是长度为1的列表,因此是非空列表,因此在条件下发生时被视为T 试试这个: (if NIL 'true 'false)

几天前我开始学习common lisp,所以请记住我是个十足的noob,以下是我的代码:

ELISP> (member nil '(2 3 nil))
(nil)

ELISP> (if (member nil '(2 3 nil))
       'true
       'false)
true

所以我的问题是“如果”如何返回true?

这种行为是正确的
(NIL)
是长度为1的列表,因此是非空列表,因此在条件下发生时被视为
T

试试这个:

(if NIL 'true 'false)  ;; false
(if () 'true 'false)    ;; false
(if '() 'true 'false)   ;; false
(if 'NIL 'true 'false)  ;; flase
;; that are all four "identities" of NIL in CL.
;; they are even `eq` to each other, since every lisp has only one 
;; physical address for NIL in their implementation.
;; I imagine it like kind of the root `/` for unix systems ...

;; but (NIL) or ('NIL) or ('()) or (()) are a lists with 1 element in them. thus evaluated to `T`.
(if '(NIL) 'true 'false) ;; true
(if '(()) 'true 'false)  ;; true
(if '('()) 'true 'false) ;; true
(if '('NIL) 'true 'false) ;; true
这就像数学中的集合论:空集没有元素,因此它是空的。但是如果你把空集放进去,它就不再是空的,而是包含元素“empty set”作为它的元素。
这可能很有哲理。这个集合的类型包含一个空集合作为其元素的想法/表示。。。这不是别的,只是一些东西。

这种行为是正确的
(NIL)
是长度为1的列表,因此是非空列表,因此在条件下发生时被视为
T

试试这个:

(if NIL 'true 'false)  ;; false
(if () 'true 'false)    ;; false
(if '() 'true 'false)   ;; false
(if 'NIL 'true 'false)  ;; flase
;; that are all four "identities" of NIL in CL.
;; they are even `eq` to each other, since every lisp has only one 
;; physical address for NIL in their implementation.
;; I imagine it like kind of the root `/` for unix systems ...

;; but (NIL) or ('NIL) or ('()) or (()) are a lists with 1 element in them. thus evaluated to `T`.
(if '(NIL) 'true 'false) ;; true
(if '(()) 'true 'false)  ;; true
(if '('()) 'true 'false) ;; true
(if '('NIL) 'true 'false) ;; true
这就像数学中的集合论:空集没有元素,因此它是空的。但是如果你把空集放进去,它就不再是空的,而是包含元素“empty set”作为它的元素。 这可能很有哲理。这个集合的类型包含一个空集合作为其元素的想法/表示。。。这只不过是些东西。

我检查过:

如果某个元素满足测试,则返回以该元素开头的列表尾部;否则返回

在本例中,您有一个三元素列表(元素为
2
3
nil

nil
是此列表的成员,因此
(成员nil'(23 nil))
返回从找到的元素开始的子列表:

(nil)  ; a one-element list
此值为true,因为只有
nil
本身为false;包含
nil
的单个元素列表不是false。

我选中了:

如果某个元素满足测试,则返回以该元素开头的列表尾部;否则返回

在本例中,您有一个三元素列表(元素为
2
3
nil

nil
是此列表的成员,因此
(成员nil'(23 nil))
返回从找到的元素开始的子列表:

(nil)  ; a one-element list
此值为true,因为只有
nil
本身为false;包含
nil
的单个元素列表不是false