Skip to content

Instantly share code, notes, and snippets.

@amalloy
Created January 31, 2011 22:18
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amalloy/c93c37345c49c47dcfa2 to your computer and use it in GitHub Desktop.
Save amalloy/c93c37345c49c47dcfa2 to your computer and use it in GitHub Desktop.
(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
Copy link

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

@bsteuber
Copy link

bsteuber commented Feb 1, 2011

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

@amalloy
Copy link
Author

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
Copy link

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