views:

95

answers:

5

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

+8  A: 

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.

Xach
+1  A: 

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

Vijay Mathew
This is only one of the possible definitions of an "atom" in Scheme.
larsmans
+1  A: 

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.

David Thornley
a symbol is not like a variable in other languages. a symbol is an 'object' with a name. In source code we write variables with symbols, but that does not make a symbol necessarily a variable. (defun foo (bar) bar) <- here BAR is a symbol in source code, but the symbol is not the variable in a compiled function FOO.
Rainer Joswig
@Rainer: Unfortunately, I don't know a good way to describe a CL symbol in a way that is immediately intelligible. It isn't just an object with a name. It doesn't even have to have a name (think `(gensym)`), and it's a rather strange sort of object.
David Thornley
Sure it has a name: (symbol-name (gensym)) -> "G1620994". It just a computed name. A symbol is an object that has a name, can be looked up by name if it is interned in a package and can be used to reference a value, a function, its package, its name and a property list.
Rainer Joswig
A: 

In Scheme, their is not formal definition of the term "atom"; it isn't even mentioned in the standard. Generally though, I would refer to a Scheme object as "atomic" if it has no internal structure, more specifically no mutable structure. So, numbers and symbols are generally considered atoms. cons pairs are not atoms, nor are vectors. As for strings, it would depend on the application, I guess.

larsmans
+1  A: 

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

Rainer Joswig