Applying a macro to a form without defining a macro

Is there a way to expand a macro without actually defining it? My situation is that I have a bunch of macros that can / cannot override clojure macros, do I need to apply these macros to a list of s-expressions?

+4
source share
2 answers

Macroexpand cannot see macros entered by the macrolet. They exist only at compile time, and macroexpand (when you call it directly) works at runtime. Your test only works because you defined when in the same way clojure.core. But the macro will solve your problem until you want to expand at runtime.

+4
source

Digging through the contributor, I found what I was looking for,

 (use ' clojure.contrib.macro-utils) (macrolet [(when [test & body] (list 'if test (cons 'do body)))] (macroexpand '(when true 4)))
(use ' clojure.contrib.macro-utils) (macrolet [(when [test & body] (list 'if test (cons 'do body)))] (macroexpand '(when true 4))) 
 (if true (do 4)) 
+2
source

All Articles