Scheme Programmer's Manual
begin - wrapper for multiple expressions
(import (rnrs)) ;R6RS
(import (rnrs base)) ;R6RS
(import (scheme r5rs)) ;R7RS
(import (scheme base)) ;R7RS
(begin expression or definition ...)
(begin expression expression ...)
keyword has different roles, depending on its context:
It may appear as a form in a
or directly nested in a begin form that appears in a body.
In this case, the begin form must have the shape specified in the
first synopsis line.
This use of begin acts as a splicing form[em]the forms inside the body
are spliced into the surrounding body, as if the begin wrapper were
not actually present.
A begin form in a
must be non-empty if it appears after the first
within the body.
It may appear as an ordinary expression and must have the shape
specified in the second synopsis line. In this case, the
are evaluated sequentially from left to right, and the values of the
are returned. This expression type is used to sequence side effects
such as assignments or input and output.
In R7RS a third form of
where it is used to begin the body of the library.
The values of the last expression are returned.
For the splicing form the rules of wherever the splice appears instead
;; This example is poor style but demonstrates the ordering
;; provided by "begin".
(define x 0)
(begin (set! x 5)
(+ x 1)) => 6
;; If "begin" did not guarantee the evaluation order then the
;; above might have evaluated to 1.
(begin (display "4 plus 1 equals ")
(display (+ 4 1)))
; prints 4 plus 1 equals 5
The splicing form of
does not usually appear in code written by programmers.
The sequencing form is sometimes used in conditional expressions,
which is a matter of personal style. Others prefer to use
form is often not used in favor of using
This form is commonly used in the output of macros which need to
generate multiple definitions and splice them into the context in
which they are expanded.
The splicing form of
does not appear in R4RS and IEEE Scheme. The sequencing form enjoys
wide compatibility among Lisp dialects, but outside of Scheme it can
be named something else (progn in Common Lisp and do in
R7RS clarifies that the splicing form may appear in the REPL.
This form can raise exceptions with the following condition types:
- &syntax (R6RS)
Raised if the splicing form is used outside of a body or as a
consequence when splicing results in an invalid body. Also raised if
the keyword is misused.
The assertions described above are errors.
Implementations may signal an error, extend the procedure's
domain of definition to include such arguments,
or fail catastrophically.
This page is part of the
It includes materials from the RnRS documents.
More information can be found at
Return to Main Contents
- RETURN VALUES
- APPLICATION USAGE
- SEE ALSO