Introduction

## 13.1 Introduction

ECLiPSe provides a general mechanism to perform macro expansion of Prolog terms. Macro expansion can be performed in 3 situations:

> read macros
>   are expanded just after a Prolog term has been read by the ECLiPSe parser. Note that the parser is not only used during compilation but by all term-reading predicates.
> compiler macros
>   are expanded only during compilation and only when a term occurs in a certain context (clause or goal).
> write macros
>   are expanded just before a Prolog term is printed by one of the output predicates

In addition to transforming a term, macros can also be source annotation aware, and provide source annotation information for the transformed term if supplied with source annotation information for the orginal term. Source annotation information is about the source and position of a term, and is provided by the predicate read_annotated/3.

Macros are attached to classes of terms specified by their functors or by their type. Macros obey the module system’s visibility rules. They may be either local or exported. The macro expansion is performed by a user-defined Prolog predicate.