[R7RS base] 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
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))
Evaluates exp0, exp1, …, then returns the result(s)
of exp0. The name is taken from MzScheme.
This is called
prog1 in CommonLisp.
begin, this does creates a new scope,
begin0 form is expanded as follows.
(receive tmp exp0 exp1 … (apply values tmp))
[SRFI-236] Evaluates exp … in an unspecified order, and returns an undefined result. This form is defined in SRFI-236.
You can use
begin to group multiple expressions, but
also specifies the order of evaluation even when it’s unnecessary.
independently, you can express the intention to the readers
that the order does not matter, and also gives the compiler
more opportunities for optimization.
As the order doesn’t matter, SRFI-236 does not specify the return
value of this form. Gauche returns
#<undef>, but the caller
shoudn’t rely on it.