Next: , Up: Control Structures   [Contents][Index]


5.13.1 Sequencing Structures

Each of the special forms in this section simply evaluates its arguments in left-to-right order. The only difference is the result returned.

The most widely used sequencing special form is progn: it evaluates all its argument forms and returns the computed value of the last one. Many other control structures are said to perform an implicit progn, this means that internally they call progn with a list of forms.

progn in Lisp is nearly analogous to a begin…end block in Pascal; it is used in much the same places—to allow you to evaluate a sequence of form where only one form was allowed (for example the “true” clause of an if structure).

Special Form: progn forms…

All of the forms are evaluated sequentially (from left-to-right), the result of the last evaluated form is the return value of the special form. If no arguments are given to progn it returns false.

(progn 'one (+ 1 1) "three")
    ⇒ "three"

(progn)
    ⇒ ()
Macro: prog1 first forms…

This special form evaluates its first form then performs an implicit progn on the rest of its arguments. The result of this structure is the computed value of the first form.

(prog1 'one (+ 1 1) "three")
    ⇒ one
Macro: prog2 first second forms…

This is similar to prog1 except that the evaluation of its second form is returned.

The first form is evaluated, then its second, then it performs an implicit progn on the remaining arguments.

(prog2 'one (+ 1 1) "three")
    ⇒ 2

Next: , Up: Control Structures   [Contents][Index]