I just added a new library to clojure.contrib: clojure.contrib.macro- 
utils. It provides three macros that are useful in writing other macros:

- macrolet (syntax like letfn) provides local macros that are active  
only inside the body of the macrolet form.

- symbol-macrolet provides local symbol macros.

- defsymbolmacro defines global symbol macros.

Symbol macros are textual replacements for symbols; they have no  
parameters. Wherever a symbol defined as a macro occurs in a form, it  
is replaced by the symbol macro's value, EXCEPT where the symbol  
names a function argument or receives a binding in a let form. The  
replacement value is again subjected to macro expansion, until the  
result no longer changes. This is the same behaviour as for standard  
macros.

While macrolet and symbol-macrolet just work as expected, global  
symbol macros require the use of the (with-symbol-macros ...) form  
around the expression(s) where they are used. This is because  
Clojure's macro system doesn't know anything about symbol macros  
otherwise. (with-symbol-macros ...) uses a complete re-implementation  
of macro expansion that knows about symbol and local macros. The same  
implementation is used by macrolet and symbol-macrolet. The  
expressions inside these forms are handed back to Clojure's compiler  
already fully expanded.

Macrolet and symbol-macrolet are most useful in defining other  
macros. Typically, a macro would expand into a form containing  
macrolet and/or symbol-macrolet for defining values or operations for  
use inside the body of the expansion.

The library also provides three functions for testing and debugging  
macro expansions:

- mexpand-1 works like macroexpand-1 but knows about symbol macros
- mexpand works like macroexpand but knows about symbol macros
- mexpand-all does a full recursive macro expansion

Any feedback is welcome.

Konrad.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to