如果原子收到列表作为参数,对原子和零的原子差异是否有任何差异?

发布于 2025-01-31 04:24:25 字数 1422 浏览 3 评论 0原文

我正在使用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列表是缺点细胞,我得出结论:

如果参数是列表,nullatom 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 and atom do have the same behavior as predicates.

Is there any counter-example for this statement? Did I miss something? Is it correct?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

短暂陪伴 2025-02-07 04:24:25

列表是:

  • 空列表,() aka nil,不是cons;
  • 或任何对象和列表的缺点。

null仅返回true true nil; atom对于任何不是缺点的对象返回true。

因此,仅限于列表nullatom仅返回true,仅对nil,是唯一的对象列表,而不是弊端,并且对于列表,等效谓词。

A list is either:

  • the empty list, () aka nil, which is not a cons;
  • or a cons of any object and a list.

null returns true only for nil; atom returns true for any object which is not a cons.

Therefore, when restricted to lists, null and atom return true only for nil, being the only object which is both a list and not a cons, and are, for lists, equivalent predicates.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文