Go to the first, previous, next, last section, table of contents.


Sequencing Structures

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

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 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 this structure. If no arguments are given to progn it returns nil.

(progn 'one (+ 1 1) "three")
    => "three"

(progn)
    => nil

Special Form: 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

Special Form: prog2 first second forms...
This is similar to prog1 except that the evaluated value 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


Go to the first, previous, next, last section, table of contents.