1 Welcome to PLT Scheme
2 Scheme Essentials
3 Built-In Datatypes
4 Expressions and Definitions
5 Programmer-Defined Datatypes
6 Modules
7 Contracts
8 Input and Output
9 Regular Expressions
10 Exceptions and Control
11 Iterations and Comprehensions
12 Pattern Matching
13 Classes and Objects
14 Units (Components)
15 Reflection and Dynamic Evaluation
16 Macros
17 Performance
18 Running and Creating Executables
19 Compilation and Configuration
20 More Libraries
Bibliography
Index
Version: 4.0.2

 

16 Macros

A macro is a syntactic form with an associated transformer that expands the original form into existing forms. To put it another way, a macro is an extension to the Scheme compiler. Most of the syntactic forms of scheme/base and scheme are actually macros that expand into a small set of core constructs.

Like many languages, Scheme provides pattern-based macros that make simple transformations easy to implement and reliable to use. Scheme also supports arbitrary macro transformers that are implemented in Scheme – or in a macro-extended variant of Scheme.

    16.1 Pattern-Based Macros

      16.1.1 define-syntax-rule

      16.1.2 Lexical Scope

      16.1.3 define-syntax and syntax-rules

      16.1.4 Matching Sequences

      16.1.5 Identifier Macros

      16.1.6 Macro-Generating Macros

      16.1.7 Extended Example: Call-by-Reference Functions

    16.2 General Macro Transformers

      16.2.1 Syntax Objects

      16.2.2 Mixing Patterns and Expressions: syntax-case

      16.2.3 with-syntax and generate-temporaries

      16.2.4 Compile and Run-Time Phases

      16.2.5 Syntax Certificates