For Gauche 0.9.5


Next: , Previous: , Up: Core syntax   [Contents][Index]

4.7 Sequencing

Special Form: begin form …

[R7RS] Evaluates forms sequentially, and returns the last result(s).

Begin doesn’t introduce new scope like let, that is, you can’t place "internal define" at the beginning of forms generally. Semantically begin behaves as if forms are spliced into the surrounding context. For example, toplevel expression like the following is the same as two toplevel definitions:

(begin (define x 1) (define y 2))

Here’s a trickier example:

(let ()
  (begin
    (define x 2)
    (begin
      (define y 3)
    ))
  (+ x y))

  ≡

(let ()
  (define x 2)
  (define y 3)
  (+ x y))
Macro: begin0 exp0 exp1 …

Evaluates exp0, exp1, …, then returns the result(s) of exp0. The name is taken from MzScheme. This is called prog1 in CommonLisp.

Unlike begin, this does creates a new scope, for the begin0 form is expanded as follows.

(receive tmp exp0
  exp1 …
  (apply values tmp))

Next: , Previous: , Up: Core syntax   [Contents][Index]