► |  | The Racket Guide

1 | Welcome to Racket
2 | Racket 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
15 | Reflection and Dynamic Evaluation
16 | Macros
17 | Creating Languages
18 | Concurrency and Synchronization
19 | Performance
20 | Parallelism
21 | Running and Creating Executables
22 | More Libraries
23 | Dialects of Racket and Scheme
24 | Command-Line Tools and Your Editor of Choice
| Bibliography
| Index

▼ | 16 | Macros

16.1 | Pattern-Based Macros
16.2 | General Macro Transformers
16.3 | Module Instantiations and Visits

top ← prev up next →

### 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 Racket compiler. Most of the syntactic forms of racket/base and racket are actually macros that expand into a small set of core constructs.

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

This chapter provides an introduction to Racket macros, but see Fear of Macros for an introduction from a different perspective.

Racket includes additional support for macro development: A macro debugger to make it easier for experienced programmers to debug their macros and for novices to study their behavior, and of macros. And the syntax/parse library for writing macros and specifying syntax that automatically validates macro uses and reports syntax errors.

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 set! Transformers
16.1.7 Macro-Generating Macros
16.1.8 Extended Example: Call-by-Reference Functions
16.2 General Macro Transformers
16.2.1 Syntax Objects
16.2.2 Macro Transformer Procedures
16.2.3 Mixing Patterns and Expressions: syntax-case
16.2.4 with-syntax and generate-temporaries
16.2.5 Compile and Run-Time Phases
16.2.6 General Phase Levels
16.2.6.1 Phases and Bindings
16.2.6.2 Phases and Modules
16.2.7 Code Inspectors and Syntax Taints
16.3 Module Instantiations and Visits
16.3.1 Declaration versus Instantiation
16.3.2 Compile-Time Instantiation
16.3.3 Visiting Modules
16.3.4 Lazy Visits via Available Modules

top ← prev up next →