Common LISP Hints: Forms and the Top-Level Loop

## 9. Forms and the Top-Level Loop

The things which you type to the LISP interpreter are called forms; the LISP interpreter repeatedly reads a form, evaluates it, and prints the result. This procedure is called the read-eval-print loop.

Some forms will cause errors. After an error, LISP will put you into the debugger so you can try to figure out what caused the error. LISP debuggers are all different; but most will respond to the command "help" or ":help" by giving some form of help.

In general, a form is either an atom (for example, a symbol, an integer, or a string) or a list. If the form is an atom, LISP evaluates it immediately. Symbols evaluate to their value; integers and strings evaluate to themselves. If the form is a list, LISP treats its first element as the name of a function; it evaluates the remaining elements recursively, and then calls the function with the values of the remaining elements as arguments.

For example, if LISP sees the form `(+ 3 4)`, it treats `+` as the name of a function. It then evaluates 3 to get 3 and 4 to get 4; finally it calls `+` with 3 and 4 as the arguments. The `+` function returns 7, which LISP prints.

The top-level loop provides some other conveniences; one particularly convenient convenience is the ability to talk about the results of previously typed forms. LISP always saves its most recent three results; it stores them as the values of the symbols `*`, `**`, and `***`. For example:

> `

>     > 3
>     3
>     > 4
>     4
>     > 5
>     5
>     > ***
>     3
>     > ***
>     4
>     > ***
>     5
>     > **
>     4
>     > *
>     4

> `