Common Lisp 中的原子和符号有什么区别?

发布于 2024-09-25 16:13:57 字数 123 浏览 4 评论 0原文

在 Common Lisp 中称为原子的东西和符号之间有什么区别吗?

这些差异是否也适用于 Lisp 家族中的其他语言?

(我知道原子在 Clojure 中具有不同的含义,但我对符号的边界感兴趣。)

Are there any differences between what in Common Lisp you'd call an atom, and a symbol?

Do these differences extend to other languages in the Lisp family?

(I'm aware that atom has a different meaning in Clojure, but I'm interested in the boundaries of what is a symbol.)

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

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

发布评论

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

评论(4

[旋木] 2024-10-02 16:13:57

在 Common Lisp 中,atom 被精确地定义为任何非 cons 的对象。有关更多详细信息,请参阅 http://l1sp.org/cl/atom

Lisp家族的其他语言我不知道。

In Common Lisp, atom is precisely defined as any object that is not a cons. See http://l1sp.org/cl/atom for more details.

I don't know about other languages in the Lisp family.

在你怀里撒娇 2024-10-02 16:13:57

“atom”通常在列表处理中看到。在 Common Lisp 中,某些东西要么是一个非空列表,要么是一个原子。过去,原子也被称为“原子符号”,这略有不同。现在,在 Common Lisp 中,原子不仅是符号,还包括除 cons 单元之外的所有其他内容(例如:字符串、数字、哈希表、流……)。

如果某物不是原子(是缺点),则可以使用操作 CAR、CDR、FIRST 和 REST。

所以atom是一组数据结构。符号是某种数据结构,它也恰好是一个原子。

'atom' is usually seen from list processing. In Common Lisp something is either a non-empty list or an atom. In former times an atom was also called 'atomic symbol', which is something slightly different. Now in Common Lisp atoms are not only symbols, but everything else which is not a cons cell (examples: strings, numbers, hashtables, streams, ...).

If something is not an atom (is a cons), the operations CAR, CDR, FIRST and REST can be used.

So atom is a group of data structure. A symbol is a certain data structure, which also happens to be an atom.

薄荷→糖丶微凉 2024-10-02 16:13:57

在Scheme中,原子是任何不是一对的东西:

> (pair? 1)
#f
> (pair? '(1 2 3))
#t
> (pair? 'a)
#f

因此符号是原子,就像数字和字符串一样。 atom 在 Common Lisp 中也有类似的定义,其中函数 (atom object) 被定义为 (not (consp object))

In Scheme, an atom is anything that is not a pair:

> (pair? 1)
#f
> (pair? '(1 2 3))
#t
> (pair? 'a)
#f

Thus symbols are atoms, just as numbers and strings. atom has a similar definition in Common Lisp, where the function (atom object) is defined to be (not (consp object)).

欢你一世 2024-10-02 16:13:57

在 Common Lisp 中,符号非常类似于其他语言中的变量,尽管更重量级(它不仅仅是一块足够大以容纳值的空白内存)。它通常是intern的,因此可以通过名称引用它,尽管它可能有匿名符号(很像 C 中的内存,您可能只能通过指针引用)。

原子是一些不是 cons 单元的值。符号是一个原子,数字、字符串和许多其他东西也是如此。 cons 单元格最常见的用途是构建列表,尽管也可以以其他方式使用它们。

In Common Lisp, a symbol is very much like a variable in other languages, although more heavyweight (it isn't just a blank piece of memory big enough to hold a value). It is usually interned so it can be referenced by name, although it's possible to have anonymous symbols (much like memory in C that you might refer to only by pointer).

An atom is some value that isn't a cons cell. A symbol is an atom, and so is a number, a string, and lots of other things. The most common use of cons cells is in making up lists, although it's possible to use them in other ways.

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