Chapter 10

Macros

Macro Names

A macro is named by a constant module binding. The macro is available to be called in any scope where this binding is accessible. Macro names can be exported and can be renamed during module importing just like any other module binding. Macro bindings are constant and cannot be changed by the assignment operator :=.

The name bound to a definition macro is the macro's define-body-word or define-list-word suffixed by -definer. This suffixing convention is analogous to the naming convention for setters and allows the define-body-word or define-list-word to be used for another purpose. The name bound to a statement macro is the macro's begin-word. The name bound to a function macro is the macro's function-word.

A named value reference is not allowed when the value of the binding is a macro, because macros are not run-time objects.

A macro cannot be named by a local binding. Macro definitions are always scoped to modules.

Attempting to create a local binding that shadows a binding to a macro is an error.

Reserved words created by a macro definition are reserved in any module where the binding that names the macro is accessible. In other modules, the same words are ordinary names. Each module has an associated syntax table used when parsing code associated with that module. The syntax table controls the lexical analyzer's assignment of names to the define-body-word, define-list-word, begin-word, and function-word categories. Importing a macro into a module makes the same modifications to that module's syntax table that would be made by defining that macro in the module. If a definition macro is renamed when it is imported, the define-body-word or define-list-word derives from the new name. If the new name does not end in -definer, the imported macro cannot be called.

A name or unreserved-name in the lexical grammar can be a backslash ('\') character followed by a word. This prevents the word from being recognized as a reserved word during parsing, but does not change which binding the word names. Quoting the name of a statement or function macro with a backslash allows the name to be mentioned without calling the macro, for example to export it from a module.

When a binding that names a macro is exported from a module that is exported from a library, clients of that library can call the macro. Information derived from the macro definition goes into the library export information part of the library description.