GNU Info

Info Node: (librep.info)Sequencing Structures

(librep.info)Sequencing Structures


Next: Conditional Structures Up: Control Structures
Enter node , (file) or (file)node

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


automatically generated by info2www version 1.2.2.9