Vicious bug

mistakes — cgrand, 22 April 2009 @ 11 h 44 min
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) 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.

0 Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

(c) 2024 Clojure and me | powered by WordPress with Barecity