The third episode of my Clojure Tip of the Day screencast is out.
You can find the video on YouTube: Clojure Tip of the Day – Episode 3: Threading macros tracing
The episode shows a quick “debugging” technique using the println
function to print intermediate values flowing through the threading macros to the standard output.
TL;DR
- For thread-first macro you can use
(doto println)
to quickly print intermediate value - Usually, it’s better and more convenient to introduce little helper function spy :
(def spy #(do (println "DEBUG:" %) %))
which then works for all threading macros - If you want to use doto-like method then you need to wrap in an anonymous function:
(#(doto % println))
(notice extract parentheses – see macro-expansion of threading macros)
Credit
Thanks to Sean Corfield and Brandom Adams for providing the tips on the Clojurians slack channel.
Thank you for posting this, it was exactly what I needed to see where my code was breaking