Next: , Up: Control Mechanisms

5.11.1 Evaluating a Sequence of Expressions

The begin syntax is used for grouping several expressions together so that they 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.

— syntax: begin expr1 expr2 ...

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.

Guile also allows the expression (begin), a begin with no sub-expressions. Such an expression returns the `unspecified' value.