A cons cell is an ordered pair of two objects, the car and the cdr.
The read syntax of a cons cell is an opening parenthesis followed by the read syntax of the car, a dot, the read syntax of the cdr and a closing parenthesis. For example a cons cell with a car of 10 and a cdr of the string `foo' would be written as,
(10 . "foo")
(cons 10 "foo")
=> (10 . "foo")
t if object is a cons cell and nil
otherwise.
(consp '(1 . 2))
=> t
(consp nil)
=> nil
(consp (cons 1 2))
=> t
In Lisp an atom is any object which is not a cons cell (and is, therefore, atomic).
t if object is an atom (not a cons cell).
Given a cons cell there are a number of operations which can be performed on it.
(car (cons 1 2))
=> 1
(car '(1 . 2))
=> 1
(cdr (cons 1 2))
=> 2
(cdr '(1 . 2))
=> 2
(setq x (cons 1 2))
=> (1 . 2)
(rplaca x 3)
=> 3
x
=> (3 . 2)
rplacd except that the cdr slot of
cons-cell is modified.
Go to the first, previous, next, last section, table of contents.