2.15 Sequencing: begin, begin0, and begin-for-syntax
Sequencing in The Racket Guide introduces begin and begin0.
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: | |||||||||||||||||
|
(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.
Example: | |||||||
|
(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:
define or define-values form: converted to a define-values-for-syntax form.
require form: content is wrapped with for-syntax.
expression form expr: converted to (define-values-for-syntax () (begin expr (values))), which effectively evaluates the expression at expansion time and, in the case of a module context, preserves the expression for future visits of the module.