1.7 Summary
Types of LISP objects:
- s-expressions :: encompass everything we have seen, including
both lists and atoms;
- lists :: sequences of s-expressions inside matching
parentheses;
- atoms :: s-expressions the LISP treats as whole things. There
are two kinds of attoms:
- numbers
- symbols (literal atoms); fill the roles of both variables and
function names
We communicate with a LISP interpreter, which tries to evaluate
each s-expression we type in. After evaluation, the intepreter prints
the value if computed. This is called the top level of LISP.
Evaluation is done according to the following rules:
- Numbers evaluate to themselves;
- Symbols evaluate to the last value assigned to them;
- Lists are evaluated by interpreting the first element as a function
name, and the rest of the list as arguments to that function. The
arguments are (usually) evaluated, and the function applied to the
resulting values. The value returned by the function is the value
of the list.
We have seen the following functions:
- Arithmetic functions, like ‘+’, ‘1+’, and ‘*’. Some of these
accept any number of arguments, and some, a fixed number. They all
cause their arguments to be evaluated.
- The special function
setq
, which assigns its first argument,
which should be a symbol, the value of its second argument.
- The system function
exit
. This is a function of no arguments
that terminates the current LISP process.