My current method: if there's a function that I know has an bug, I copy bits and pieces of it into the REPL and evaluate to see if the output is what I expect. To set it up, I have to def the arguments to the function as dummy input. Not terribly time-consuming, but I know there's a more efficient way.
Any suggestions?
Does this macro help? It turns a let into a series of defs, so that you can evaluate the subexpressions:
(defmacro def-let
"like let, but binds the expressions globally."
[bindings & more]
(let [let-expr (macroexpand `(let ~bindings))
names-values (partition 2 (second let-expr))
defs (map #(cons 'def %) names-values)]
(concat (list 'do) defs more)))
I wrote an explanation here: http://www.learningclojure.com/2010/09/astonishing-macro-of-narayan-singhal.html
After reading up on this, my new favorite method is to add
(swank.core/break)
inside the function and inspect values by pressing 't'. (I'm using swank-clojure)
Source: http://hugoduncan.org/post/2010/swank_clojure_gets_a_break_with_the_local_environment.xhtml
for bugs spanning several functions I like the Trace macro for reporting the calls and returns of each function.
I wrote an tracing library which can show you what value every element returned.
http://github.com/hozumi/eyewrap
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With