Vicious bug
- What’s wrong with this code
(do (defmacro foobar [x] (doto x println)) (foobar (+ 1 1)))
? - Nothing.
- Run it again.
- The first time,
foobar
is treated as a function (its argument has been evaluated) becausefoobar
is unknown before the whole top-level expression is compiled.
The second time, the var namedfoobar
preexists 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.