Next: Syntax Case, Previous: Macros, Up: Procedures and Macros
syntax-rules System
R5RS defines an alternative system for macro and syntax transformations
using the keywords define-syntax, let-syntax,
letrec-syntax and syntax-rules.
The main difference between the R5RS system and the traditional macros of the previous section is how the transformation is specified. In R5RS, rather than permitting a macro definition to return an arbitrary expression, the transformation is specified in a pattern language that
caddr etc.
The last point is commonly referred to as being hygienic: the R5RS
syntax-case system provides hygienic macros.
For example, the R5RS pattern language for the false-if-exception
example of the previous section looks like this:
(syntax-rules ()
((_ expr)
(catch #t
(lambda () expr)
(lambda args #f))))
In Guile, the syntax-rules system is provided by the (ice-9
syncase) module. To make these facilities available in your code,
include the expression (use-syntax (ice-9 syncase)) (see Using Guile Modules) before the first usage of define-syntax etc. If
you are writing a Scheme module, you can alternatively include the form
#:use-syntax (ice-9 syncase) in your define-module
declaration (see Creating Guile Modules).