chickadee » chicken » macros » define-syntax

(define-syntax IDENTIFIER TRANSFORMER)syntax

Defines a macro named IDENTIFIER that will transform an expression with IDENTIFIER in operator position according to TRANSFORMER. The transformer expression must be the result of a call to er-macro-transformer or ir-macro-transformer, or it must be a syntax-rules form. If syntax-rules is used, the usual R5RS semantics apply. If TRANSFORMER is a transformer, then its transformer procedure will be called on expansion with the complete s-expression of the macro invocation, a rename procedure that hygienically renames identifiers and a comparison procedure that compares (possibly renamed) identifiers (see the section "Explicit renaming macros" below for a detailed explanation on non-R5RS macros).

define-syntax may be used to define local macros that are visible throughout the rest of the body in which the definition occurred, i.e.

 (let ()
   ...
   (define-syntax foo ...)
   (define-syntax bar ...)
   ...)

is expanded into

 (let ()
   ...
   (letrec-syntax ((foo ...) (bar ...))
     ...) )

syntax-rules supports SRFI-46 in allowing the ellipsis identifier to be user-defined by passing it as the first argument to the syntax-rules form. Also, "tail" patterns of the form

 (syntax-rules ()
   ((_ (a b ... c) 
     ...

are supported.

The effect of destructively modifying the s-expression passed to a transformer procedure is undefined.