Next: stdlib syntax-case intro unwrap, Up: stdlib syntax-case intro [Index]
Let’s say that infix
is a syntactic keyword; we may have a
library like this:
(library (infix) (export infix) (import (rnrs)) (define-syntax infix (lambda (use) ---) ;this is the transformer function ))
then in the following program S–expression:
(import (rnrs) (infix)) (let-values (((port getter) (open-string-output-port))) (display (infix 1 + 2) port) (getter))
the subexpression:
(infix 1 + 2)
is a macro use of the infix
syntax and it becomes the
input form of the transformer function of infix
; the input
form is extracted from the whole S–expression, transformed, let’s say,
into the output form:
(begin 3)
and put back:
(import (rnrs) (infix)) (let-values (((port getter) (open-string-output-port))) (display (begin 3) port) (getter))
A number of rules are used not to mess up bidings in the input and output forms; these are introduced in Hygiene.
The single argument transformer functions are applied to is a syntax object representing the input form; the standard defines wrapped syntax objects and unwrapped syntax objects. Both wrapped and unwrapped objects can be used to represent the same informations, but wrapped objects can be more efficient in terms of consumed resources.