Next: , Up: expander intro   [Index]


15.1.1 Primitive core macros, primitive non–core macros, user–defined macros

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?

Primitive core macros

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?

Core macros can establish new syntactic bindings by direct access to the data structures representing the lexical environment.

Primitive non–core macros

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.

User–defined macros

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: , Up: expander intro   [Index]