1 Language Model
2 Syntactic Forms
3 Datatypes
4 Structures
5 Classes and Objects
6 Units
7 Contracts
8 Pattern Matching
9 Control Flow
10 Concurrency
11 Macros
12 Input and Output
13 Reflection and Security
14 Operating System
15 Memory Management
16 Running PLT Scheme
Bibliography
Index
On this page:
begin
begin0
begin-for-syntax
Version: 4.0.2

 

2.15 Sequencing: begin, begin0, and begin-for-syntax

Sequencing in Guide: PLT Scheme introduces begin and begin0.

(begin form ...)

(begin expr ...+)

The first form applies when begin appears at the top level, at module level, or in an internal-definition position (before any expression in the internal-definition sequence). In that case, the begin form is equivalent to splicing the forms into the enclosing context.

The second form applies for begin in an expression position. In that case, the exprs are evaluated in order, and the results are ignored for all but the last expr. The last expr is in tail position with respect to the begin form.

Examples:

  > (begin

      (define x 10)

      x)

  10

  > (+ 1 (begin

           (printf "hi\n")

           2))

  hi

  3

  > (let-values ([(x y) (begin

                          (values 1 2 3)

                          (values 1 2))])

     (list x y))

  (1 2)

(begin0 expr body ...+)

Evaluates the expr, then evaluates the bodys, ignoring the body results. The results of the expr are the results of the begin0 form, but the expr is in tail position only if no bodys are present.

Examples:

  > (begin0

      (values 1 2)

      (printf "hi\n"))

  hi

  1

  2

(begin-for-syntax form ...)

Allowed only in a top-level context or module context. Each form is partially expanded (see Partial Expansion) to determine one of the following classifications: