4 ms·
What you call 'atom' is actually called 'symbol' in Lisp. Keywords are in Common Lisp a subset of symbols, those who are in the package 'KEYWORD'. Keywords also
by lispm 10y ago
What you call 'atom' is actually called 'symbol' in Lisp. Keywords are in Common Lisp a subset of symbols, those who are in the package 'KEYWORD'. Keywords also have themselves as value. Thus keywords evaluate to themselves.
'atom' means something else: 'not cons'. Anything that is not a cons cell (the two-pointer building block of linked lists) is an atom: numbers, characters, strings, symbols, arrays, ...
Thus a string is an atom, too.
CL-USER 1 > (typep "foobar" 'atom)
T
CL-USER 2 > (typep 4 'atom)
T
CL-USER 3 > (typep 'foobar 'atom)
T
CL-USER 4 > (typep '(foo . bar) 'atom)
NIL
True though, symbols (not atoms) are often used as keys for key/value data structures like assoc lists, property lists, hash tables, CLOS instances and others.
Common Lisp also allows symbols to have arbitrary names. It uses | and \ as escape characters in symbols.
CL-USER 11 > '((person |Marvin Minsky|)
(|KNOWN FOR| |Artificial Intelligence Research|)
(lab |MIT AI Lab|))
((PERSON |Marvin Minsky|)
(KNOWN\ FOR |Artificial Intelligence Research|)
(LAB |MIT AI Lab|))
CL-USER 12 > (setf mm *)
((PERSON |Marvin Minsky|)
(KNOWN\ FOR |Artificial Intelligence Research|)
(LAB |MIT AI Lab|))
CL-USER 13 > (assoc '|KNOWN FOR| mm)
(KNOWN\ FOR |Artificial Intelligence Research|)
Symbols are by default interned in a special data structure and are looked up at read-time. Thus they are compared by pointer identity. In Common Lisp this data structure is called a package and there can be more than one package.
- db48x 10y agoYes, "symbol" is the correct term. Must have been a brain fart.