erp0.arc
(mac erp (x) (w/uniq (gx) `(let ,gx ,x (w/stdout (stderr) (pr ',x ": ") (write ,gx) (prn)) ,gx)))
Consider the typical debug print statement:
(prn "foo: " foo)
notice the redundancy... I want to see what value I’m printing out, so I have to type “foo” twice.
erp is a macro prints out 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.
The message is printed to stderr so that erp can be called from inside of a defop, and the message will print on Arc’s REPL instead of appearing in the middle of the web page.
For example, if I’m looking at
(+ 3 (/ 4 2) 5)
and I’m thinking, “wait, what is (/ 4 2) evaluating to again?”, I stick in erp:
arc> (+ 3 (erp (/ 4 2)) 5) (/ 4 2): 2 10 arc>
As drcode pointed out to me, by using Arc’s colon syntax we can even avoid the extra parentheses:
arc> (+ 3 (erp:/ 4 2) 5) (/ 4 2): 2 10 arc>
Why “erp”? Well, A) it’s short for “stderr print”, and B) it’s what I’m usually thinking in the middle of a debug session... :-)
wget http://hacks.catdancer.ws/erp0.arc mzscheme -m -f as.scm (load "erp0.arc")