开发者

What is the difference between an atom and a symbol in Common Lisp?

开发者 https://www.devze.com 2023-01-18 11:58 出处:网络
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?

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.)


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.


'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.


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)).


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消