Node:begin, Next:, Up:Control Mechanisms

26.1 Evaluating a Sequence of Expressions

begin is used for grouping several expression together so that they syntactically are treated as if they were one expression. This is particularly important when syntactic expressions are used which only allow one expression, but the programmer wants to use more than one expression in that place. As an example, consider the conditional expression below:

(if (> x 0)
    (begin (display "greater") (newline)))

If the two calls to display and newline were not embedded in a begin-statement, the call to newline would get misinterpreted as the else-branch of the if-expression.

begin expr1 expr2 ... syntax
The expression(s) are evaluated in left-to-right order and the value of the last expression is returned as the value of the begin-expression. This expression type is used when the expressions before the last one are evaluated for their side effects.