Clojure and me has moved.

Wednesday, April 22, 2009

Vicious bug

This post has moved, go to its new location
What's wrong with this code (do (defmacro foobar [x] (doto x println)) (foobar (+ 1 1)))?
Run it again.
The first time, foobar is treated as a function (its argument has been evaluated) because foobar is unknown before the whole top-level expression is compiled.
The second time, the var named foobar 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.

No comments: