Node: Binding constructs for syntactic keywords, Next: Pattern language, Previous: Macros, Up: Macros
Let-syntax
and letrec-syntax
are
analogous to let
and letrec
, but they bind
syntactic keywords to macro transformers instead of binding variables
to locations that contain values. Syntactic keywords may also be
bound at top level; see section Syntax definitions.
let-syntax <bindings> <body> | syntax |
Syntax: <Bindings> should have the form ((<keyword> <transformer spec>) ...) Each <keyword> is an identifier,
each <transformer spec> is an instance of Semantics:
The <body> is expanded in the syntactic environment
obtained by extending the syntactic environment of the
(let-syntax ((when (syntax-rules () ((when test stmt1 stmt2 ...) (if test (begin stmt1 stmt2 ...)))))) (let ((if #t)) (when if (set! if 'now)) if)) ==> now (let ((x 'outer)) (let-syntax ((m (syntax-rules () ((m) x)))) (let ((x 'inner)) (m)))) ==> outer |
letrec-syntax <bindings> <body> | syntax |
Syntax:
Same as for Semantics:
The <body> is expanded in the syntactic environment obtained by
extending the syntactic environment of the (letrec-syntax ((my-or (syntax-rules () ((my-or) #f) ((my-or e) e) ((my-or e1 e2 ...) (let ((temp e1)) (if temp temp (my-or e2 ...))))))) (let ((x #f) (y 7) (temp 8) (let odd?) (if even?)) (my-or x (let temp) (if y) y))) ==> 7 |