Next: , Previous: , Up: Special Forms   [Contents][Index]


2.8 Sequencing

The begin special form is used to evaluate expressions in a particular order.

special form: begin expression expression …

The expressions are evaluated sequentially from left to right, and the value of the last expression is returned. This expression type is used to sequence side effects such as input and output.

(define x 0)
(begin (set! x 5)
       (+ x 1))                 ⇒  6

(begin (display "4 plus 1 equals ")
       (display (+ 4 1)))
                                -|  4 plus 1 equals 5
                                ⇒  unspecified

Often the use of begin is unnecessary, because many special forms already support sequences of expressions (that is, they have an implicit begin). Some of these special forms are:

case
cond
define          ;“procedure define” only
do
fluid-let
lambda
let
let*
letrec
named-lambda

The obsolete special form sequence is identical to begin. It should not be used in new code.