13. Bigloo -- Macro expansion

13. Bigloo -- Macro expansion

Browsing

Home: Bigloo
A ``practical Scheme compiler''
for Bigloo version 2.5a
April 2002

Previous chapter: Eval and code interpretation
Next chapter: Command Line Parsing


Macro expansion

13.1 Expansion passing style macros
13.2 Revised(5) macro expansion


Chapters

Copyright
Acknowledgements
1. Table of contents
2. Overview of Bigloo
3. Modules
4. Core Language
5. Standard Library
6. Pattern Matching
7. Object System
8. Threads
9. Regular parsing
10. Lalr(1) parsing
11. Errors and Assertions
12. Eval and code interpretation
13. Macro expansion
14. Command Line Parsing
15. Explicit typing
16. The C interface
17. The Java interface
18. Bigloo Libraries
19. SRFIs
20. DSSSL support
21. Compiler description
22. User Extensions
23. Bigloo Development Environment
24. Global Index
25. Library Index
Bibliography


Bigloo make uses of two macro expansion system. The one based on the expansion passing style [Dybvig et al. 86] and the one advocated by the R5RS, for which see http://www.inria.fr/mimosa/fp/Bigloo/doc/r5rs.html.

13.1 Expansion passing style macros

define-expander name procbigloo syntax
This form defines an expander, name, where proc is a procedure of two arguments: a form to macro-expand, and an expander.

define-macro (name [args]...) bodybigloo syntax
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 and define-macro are used by both the compiler and the interpreter.

Here is an example of a 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)))


13.2 Revised(5) macro expansion

Bigloo support the Revised(5) Report on the Scheme programming language. For a detailed documentation see See info-file `r5rs.info', .

let-syntax (binding...) bodysyntax
letrec-syntax (binding...) bodysyntax
define-syntax keyword transformersyntax
These three forms are compatible with the description of the Revised(5) Report on the Algorithmic Language Scheme. They are enable within the compiler only when the hygien option is used. If you try to compile a program that contains a syntax form (either define-syntax, let-syntax or letrec-syntax) the compiler will produce an error like:

*** ERROR:bigloo:TOP-LEVEL:
Illegal form -- ()
The default behavior of the compiler is to not recognize these forms when compiling nor interpreting. To enable these form with the interpreter, set the variable *hygien?* to #t.

Hygien is expensive even when not used (but enabled) that's why its default behavior is to be disabled.

*hygien?*bigloo variable
If set to #t enable the let-syntax, letrec-syntax and define-syntax under the interpreter (the default value for this variable is #f).







This
Scribe page has been generated by scribeinfo.
Last update Thu Apr 25 09:40:15 2002