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

Macros

Scheme is very procedure-oriented, but procedures can't do everything, at least not in a way that is syntactically pretty and efficient.

Sometimes you want to define your own control structures and data-defining expressions that can't be clearly and efficiently expressed as procedures, and for this Scheme provides a syntactic extension or macro facility.

With macros, you can define stereotyped pieces of code, and how to transform them for different purposes.

You might have had bad experiences with macros in other languages, like C, but Scheme's macro system is special. It's an extremely powerful mechanism for abstracting over programs and putting things together in special ways.

As we'll see in a later chapter, with Scheme macros you can effectively reprogram the compiler to change the language and its implementation. This is not something you'll need to do often--most of the time you'll do fine with normal programming and higher-order procedures--but sometimes it's extremely useful for building your own extended version of Scheme to solve particular kinds of problems, or for automating tedious and repetitive aspects of program construction.


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