Chapter 2

Syntax


Macros

A macro is an extension to the core language that can be defined by the programmer, by the implementation, or as part of the Dylan language specification. Much of the grammatical structure of Dylan is built with macros. A macro defines the meaning of one construct in terms of another construct. The original construct is the call to the macro. The replacement construct is the expansion of the macro. The compiler processes the expansion in place of the call.

Portions of the call to a macro are substituted into part of the macro definition to create the expansion. This substitution preserves the meanings of names. In other words, each name inserted into the expansion from the macro call refers to the same binding that it referred to in the call, and each name inserted into the expansion from the macro definition refers to the same binding that it referred to in the definition.

A macro is named by a binding and thus is available for use wherever that binding is visible. There are three kinds of macros: defining macros, which extend the available set of definitions; statement macros, which extend the available set of statements; and function macros, which look syntactically like function calls but have more flexible semantics.