On 13.05.2009, at 08:32, Konrad Hinsen wrote:
> I have done exactly that recently when writing clojure.contrib.macro-
> utils, which contains a full macro expansion engine because that's
> the only way to implement symbol macros and local macros. It was an
> interesting exercice in macro programming.
It just occurred to me that local macros are probably a very good way
for implementing the kind of optimization you have in mind:
(macrolet [(fn + [& ops] ...)]
(expr1)
(expr2)
...)
takes care of not touching occurrences of + that should be left as
is, and correctly interacts with other macros. Inside the (fn + ...),
you just have to make sure that your output forms use clojure.core/+
instead of an unqualified +, to prevent the macro from being executed
in an endless loop. Using a local macro will even make sure that +
passed as a parameter to other functions is not touched. The only
limitation is that code using clojure.core/+ explicitly is not
modified. This may well be an advantage, as it provides an escape
mechanism from optimization.
Konrad.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---