| I never end up using a debugger with dynamic languages. I have nothing against debuggers, and I'd use one if I found it useful to me, but when I'm in the middle of my code and wanting to find out what's going on I just stick in the plain old debug print statement: (prn "i: " i)
But, notice the redundancy, I type "i" twice. So I wrote a macro "erp" (short for "stderr print"), which prints to stderr its argument, both literally and what it evaluates to. And, it returns the result as well, so it can be inserted in the middle of some code.For example, if I'm looking at (+ 3 (/ 4 2) 5)
and thinking, "wait, what is (/ 4 2) evaluating to again?", I stick in erp: arc> (+ 3 (erp (/ 4 2)) 5)
(/ 4 2): 2
10
arc>
I find that most often just seeing the literal expression that's being printed gives me enough context to tell me which one it is. (mac erp (x)
(w/uniq (gx)
`(let ,gx ,x
(w/stdout (stderr)
(pr ',x ": ") (write ,gx) (prn))
,gx)))
|