Go to the first, previous, next, last section, table of contents.

Quasiquotation and Macros

Scheme provides facilities for transforming expressions automatically to create new expressions. These facilities are called quasiquotation and syntax extension (or "macros"). Transformational programming is one of the most powerful features of Scheme.

Quasiquotation allows you to specify patterns that can be used to construct data structures, and also specify how to fill in "holes" in the patterns. In effect, you can define a template for a data structure, much like a quoted data structure, but also specify how to fill in holes to create variations on the data structure.

Syntax extension allows you to do something very similar for code. You can write "macros" that specify most of an expression, and you can fill in the holes in these templates to create particular expressions. With macros, you can write "templates" for programs, which you can customize by filling in the holes. This lets you create both code-structuring and data-structuring facilities that express stereotyped patterns with variations.

[ Scheme macros are actually more powerful than this, however, because you can use them to analyze code before transforming it... sort of... ]

With Scheme macros, you can define new control constructs, data structuring facilities, full-blown object systems with inheritance, parameterized coding facilities (like C++ templates), and other more application-specific facilities to make your life easier.


Go to the first, previous, next, last section, table of contents.