- What’s wrong with this code
(do (defmacro foobar [x] (doto x println)) (foobar (+ 1 1)))?
- Run it again.
- The first time,
foobaris treated as a function (its argument has been evaluated) because
foobaris unknown before the whole top-level expression is compiled.
The second time, the var named
foobarpreexists and is a macro,
(foobar (+ 1 1))is expanded.
This behaviour bit me while using
with-test to test macros. It’s the kind of bug that goes unnoticed while developing incrementally and evaluating in the same REPL, it was waiting for me to start a fresh REPL.