如果原子收到列表作为参数,对原子和零的原子差异是否有任何差异?
我正在使用SBCL,Emacs和Slime。根据符号计算的书籍:通用LISP 的温和介绍,atom
的定义是:
原子谓词返回t,如果其输入是弊端的其他任何内容 单元格。
另一方面:
零谓词如果输入为零,则返回t。它的行为是一样的 作为不是谓词。
使用repl and 仅列出作为参数,我只能想到它们检索相同结果的示例:
CL-USER> (atom (cons 1 nil))
NIL
CL-USER> (null (cons 1 nil))
NIL
CL-USER> (atom (cons 1 (cons 2 nil)))
NIL
CL-USER> (null (cons 1 (cons 2 nil)))
NIL
CL-USER> (atom (cons 1 2))
NIL
CL-USER> (null (cons 1 2))
NIL
CL-USER> (atom '())
T
CL-USER> (null '())
T
CL-USER> (null nil) ;; just changing notation from previous
T
CL-USER> (atom nil) ;; just changing notation from previous
T
CL-USER> (atom '(1 . 2)) ;; just changing notation from previous
NIL
CL-USER> (null '(1 . 2)) ;; just changing notation from previous
NIL
CL-USER> (atom '(1 2)) ;; just changing notation from previous
NIL
CL-USER> (null '(1 2)) ;; just changing notation from previous
NIL
CL-USER> (atom '(1)) ;; just changing notation from previous
NIL
CL-USER> (null '(1)) ;; just changing notation from previous
NIL
基于上面的定义,示例,并考虑到 nonthen-notemply列表是缺点细胞,我得出结论:
如果参数是列表,
null
和atom
do 具有与谓词相同的行为。
此语句有任何反例吗?我想念什么吗?正确吗?
I am using SBCL, Emacs, and Slime. According to the book Symbolic Computation: A gentle introduction to Common Lisp, the definition of atom
is:
The ATOM predicate returns T if its input is anything other than a cons
cell.
On the other hand:
The NULL predicate returns T if its input is NIL. Its behavior is the same
as the NOT predicate.
Using the REPL and taking only lists as arguments, I can only think of examples in which they retrieve the same results:
CL-USER> (atom (cons 1 nil))
NIL
CL-USER> (null (cons 1 nil))
NIL
CL-USER> (atom (cons 1 (cons 2 nil)))
NIL
CL-USER> (null (cons 1 (cons 2 nil)))
NIL
CL-USER> (atom (cons 1 2))
NIL
CL-USER> (null (cons 1 2))
NIL
CL-USER> (atom '())
T
CL-USER> (null '())
T
CL-USER> (null nil) ;; just changing notation from previous
T
CL-USER> (atom nil) ;; just changing notation from previous
T
CL-USER> (atom '(1 . 2)) ;; just changing notation from previous
NIL
CL-USER> (null '(1 . 2)) ;; just changing notation from previous
NIL
CL-USER> (atom '(1 2)) ;; just changing notation from previous
NIL
CL-USER> (null '(1 2)) ;; just changing notation from previous
NIL
CL-USER> (atom '(1)) ;; just changing notation from previous
NIL
CL-USER> (null '(1)) ;; just changing notation from previous
NIL
Based on the definitions, the examples above, and considering that non-empty lists are cons cells, I am concluding that:
if the argument is a list,
null
andatom
do have the same behavior as predicates.
Is there any counter-example for this statement? Did I miss something? Is it correct?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
列表是:
()
akanil
,不是cons;null
仅返回true truenil
;atom
对于任何不是缺点的对象返回true。因此,仅限于列表,
null
和atom
仅返回true,仅对nil
,是唯一的对象列表,而不是弊端,并且对于列表,等效谓词。A list is either:
()
akanil
, which is not a cons;null
returns true only fornil
;atom
returns true for any object which is not a cons.Therefore, when restricted to lists,
null
andatom
return true only fornil
, being the only object which is both a list and not a cons, and are, for lists, equivalent predicates.