Instantly share code, notes, and snippets.

Embed
What would you like to do?
(defmacro ?
"A useful debugging tool when you can't figure out what's going on:
wrap a form with ?, and the form will be printed alongside
its result. The result will still be passed along."
[val]
`(let [x# ~val]
(prn '~val '~'is x#)
x#))
@laurentpetit

This comment has been minimized.

Copy link

laurentpetit commented Feb 1, 2011

Hmmm, there something like that named 'spy' in clojure contrib, AFAIK

@bsteuber

This comment has been minimized.

Copy link

bsteuber commented Feb 1, 2011

I like '~' - reminds me of the good old days doing macro-writing macros in Common Lisp :)

@amalloy

This comment has been minimized.

Copy link
Owner

amalloy commented Feb 1, 2011

Yes, spy does this, but imo not as well. It uses (str '~expr) for one thing, instead of pr-str, which makes it hard to tell exactly what types things are. It also outputs to the debug log, which requires that you configure logging for your program. Most of the time I don't want to bother with that.

@laurentpetit

This comment has been minimized.

Copy link

laurentpetit commented Feb 1, 2011

Right. And I also tend to rewrite such a little function, since it's even easier than trying to remember in what clojure contrib it lives, grab the dependency if I don't have it yet ... such a little function could maybe have its place somewhere in clojure core ? clojure.core, or clojure.repl ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment