www.delorie.com/gnu/docs/guile/guile_263.html   search  
 
Buy GNU books!


Guile Reference Manual

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

23.6 The R5RS 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

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 section 31.3.2 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 section 31.3.3 Creating Guile Modules).

23.6.1 The syntax-rules Pattern Language  The syntax-rules pattern language.
23.6.2 Top Level Syntax Definitions  Top level syntax definitions.
23.6.3 Local Syntax Definitions  Local syntax definitions.


  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003