21.8 Summary
In this chapter, we introduced macros by explaining their purpose as a language-extension tool, and by showing a range of Dylan macros. Macros can be useful when you want to tailor the language to express a particular problem domain more concisely.
Table 21.1 summarizes how constraints control pattern-variable matches.
Table 21.1 Pattern constraints.Constraint
| Matches
|
|---|
token
| a lexeme (a Dylan word), including literal strings, symbols, and numbers and punctuation
|
name
| a Dylan identifier, including reserved identifiers, such as define, end, and operators such as +, or *
|
variable
| either variable or variable :: <type>, useful for macros that mimic variable binding (automatically drops the :: <type>, as appropriate on substitution)
|
expression
| a well-formed Dylan expression — a constant, such as 37; a variable, such as *my-position*; a function call, such as get-current-time(); a statement, such as if (test) 12 else try() end; or a binary operand series, such as x + y * z
|
body
| a well-formed Dylan body — a sequence of semicolon-separated constituents, each constituent being either a definition, local declaration, or expression
|
case-body
| a Dylan case statement body
|
*
| any sequence of Dylan tokens and parsed forms
|
N Feinberg/S E Keene/R Mathews/P Tucker Withington, DYLAN PROGRAMMING, (c) 1997 Harlequin Inc. Reproduced by permission of Addison-Wesley Longman Publishing Company, Inc. All rights reserved. No further copying, downloading or transmitting of this material is allowed without the prior written permission of the publisher.