Next: expander intro times, Up: expander intro [Index]
A big portion of what the expander does is processing macros; converting input syntactic forms with format:
(?keyword ?subform …)
into some output syntactic forms. What kind of macros are implemented? And which part of the expander’s source code implements them?
These are basic syntaxes into which all the other macros are expanded; despite being called “core”, they are neither part of the expanded language nor of the core language. Core macros are split into three groups, those that can appear in definition–context only:
define define-syntax define-alias define-fluid-syntax module library begin import export set! stale-when begin-for-syntax
and maybe others; those that can appear in expression–context only:
foreign-call quote syntax-case syntax letrec letrec* if lambda case-lambda fluid-let-syntax struct-type-descriptor struct-type-and-struct? record-type-descriptor record-constructor-descriptor type-descriptor is-a? splice-first-expand predicate-procedure-argument-validation predicate-return-value-validation
and maybe others; those that can appear in both definition–context and expression–context:
let-syntax letrec-syntax
Which part of the expander’s source code implements core macros?
chi-body*
. The implementation is
sophisticated because, in a body, syntactic bindings defined by
define-syntax
must be processed before syntactic bindings
defined by define
, so multiple passes are required.
core-macro-transformer
. Such transformers are applied to input
forms by the function chi-expr
.
A core transformer function accepts as arguments: a syntax object
representing the input form; values representing the lexical context in
which the input form is present. A core transformer function returns an
instance of type <psi>
representing an expanded language
expression.
chi-body*
and one
in the function chi-expr
.
Core macros can establish new syntactic bindings by direct access to the data structures representing the lexical environment.
These are macros that expand themselves into uses of core macros or other non–core macros; they have a proper transformer function accepting, as single argument, a syntax object representing the input form and returning, as single value, a syntax object representing the output form. The only difference between a non–core macro and a user–defined macro is that the former is integrated in the expander.
Non–core macro transformers are selected by the function
non-core-macro-transformer
. The transformers are applied to
input forms by the function chi-expr
.
These are macros defined by define-syntax
, let-syntax
,
letrec-syntax
, define-fluid-syntax
and their
derivatives. Such syntaxes expand themselves into uses of core or
non–core macros. Their transformer functions accept, as single
argument, a syntax object representing the input form and return, as
single value, a syntax object representing the output form.
Next: expander intro times, Up: expander intro [Index]