Next: Iteration, Previous: Conditionals, Up: Special Forms
The begin
special form is used to evaluate expressions in a
particular order.
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 implicitbegin
). Some of these special forms are:case cond define ;``proceduredefine
'' only do fluid-let lambda let let* letrec named-lambdaThe obsolete special form
sequence
is identical tobegin
. It should not be used in new code.