[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
24.1 Expansion passing style macros
- bigloo syntax: define-expander name proc
This form defines an expander, name, where proc is a procedure of two arguments: a form to macro-expand, and an expander.
- bigloo syntax: define-macro (name [args]…) body
This form is itself macro-expanded into a
define-expander
form.Macro expanders cannot be exported or imported since there is no way to specify expanders in a module declaration.
Macros defined with
define-expander
anddefine-macro
are used by both the compiler and the interpreter.
Here is an example of an expander:
(define-expander when (lambda (x e) (match-case x ((?- ?test . ?exps) (e `(if ,test (begin ,@exps)) e)) (else (error "when" "illegal form" x))))) (when (> a 0) (print a) a) → (if (> a 0) (begin (print a) a))
The same example can written with a define-macro
form:
(define-macro (when test . exps) `(if ,test (begin ,@exps)))
This document was generated on March 31, 2014 using texi2html 5.0.