Definitions and Basic Functions
Definitions
- An atom is either an integer or an identifier.
- A list is a left parenthesis, followed by zero or more S-expressions, followed by a right parenthesis.
- An S-expression is an atom or a list.
NIL
means “false.”
NIL
is also the name for the empty list, and may be written as ( )
.
T
means “true,” but actually anything that is not NIL
is “true.”
Basic Functions
- DEFUN is used to define new functions.
- QUOTE takes a single S-expression as a parameter, and returns that S-expression, unevaluated, as its result.
- The CAR of a nonempty list is the first element in that list.
- The CDR of a nonempty list is the list with its first element removed.
- The CONS of an S-expression to a list is the list with the S-expression inserted at the beginning, as a new first element.
Note that the
CAR
of this new list is the given S-expression, while the CDR
is the original list.
- EQ compares two atoms for equality (identity) and returns “true” if the atoms are the same,
NIL
if they are different.
- ATOM of an S-expression is “true” if the S-expression is an atom, and
NIL
otherwise.
- NULL of an S-expression is “true” if the S-expression is the empty list (that is,
NIL
), and NIL
otherwise.