Next: Primitive Syntax and Expanding Up: Macros Previous: Identifier Macros

# Expansion Time Binding and Evaluation

Expansion time is the time at which macro and identifier macro definition values are evaluated and macro procedures are invoked. Macros, identifier macros, and primitive syntax are expansion-time values. General expansion-time values can be defined with the `define-expansion-time` and `let-expansion-time` syntactic forms. Scoped expansion-time bindings can be obtained with `local-expansion-time-value` or `global-expansion-time-value`, and scoping information is available through `local-expansion-time-bound?`.

- `(define-expansion-time id expr)` evaluates expr at run time and binds it as an expansion-time value to the global variable id. This form is treated specially by `compile-file` (see section 15.2.5).
- `(let-expansion-time id expr body-expr )` evaluates expr at expansion time and binds an expansion-time value to id within the body-exprs. The run-time result of a `let-expansion-time` expression is the result of evaluating the last body-expr.

  As with `define-macro`, an internal `define-expansion-time` expression is transformed into a `let-expansion-time` expression.

- `(local-expansion-time-value symbol)` returns the expansion-time binding of symbol in the scope of the expression currently being expanded. The identifier corresponding to symbol must have been bound to an expansion-time value by `define-expansion-time` or `let-expansion-time`, otherwise the `exn:misc` exception is raised. If `local-expansion-time-value` is invoked at run time, the `exn:misc` exception is raised.
- `(global-expansion-time-value symbol)` is like `(local-expansion-time-value symbol)`, but symbol must be bound in the current namespace (and lexical bindings are ignored).
- `(local-expansion-time-bound? symbol)` returns `#t` if the identifier symbol is locally bound, `#f` otherwise. If `local-expansion-time-bound?` is invoked at run time, the `exn:misc` exception is raised.
- `(expansion-time-value? v)` returns `#t` if v is a value created with `define-expansion-time`, `#f` otherwise. Note that `expansion-time-value?` cannot be applied directly to expansion-time identifiers, but expansion-time values can be obtained indirectly with `global-defined-value`.
- `begin-elaboration-time` `(begin-elaboration-time body-expr )` evaluates each body-expr at expansion time. Once the body-exprs are evaluated, the entire form is replaced with the S-expression result of the last body-expr, and macro expansion continues. This form is treated specially by `compile-file` (see section 15.2.5).

Next: Primitive Syntax and Expanding Up: Macros Previous: Identifier Macros