https://www.assembla.com/spaces/clojure/tickets/415-smarter-assert-(prints-locals)
Thoughts?
Awesome idea. I don't know how many times I have had to tweak code and
re-run to figure out *why* an assertion failed (regardless of
programming language).
One problem I can think of is that locals may contain things that you
definitely do not want to print (infinite sequences, very large data
structures, even sequences whose consumption implies some kind of
side-effect).
Unfortunately I don't have a suggestion as to how to get around that
problem that does not involve somehow manually selecting which locals
are to be printed, significantly reducing the out-of-the-box
usefulness of the macro.
--
/ Peter Schuller
Hmm, maybe something pragmatic like filtering types and applying some
custom behavior for each. For example a map could be printed if it
contains less than N associations (or else print up to N
associations), and values in said map never printed except if they are
primitives or non-clojure data structures (that was not terribly
thought-through).
Might it be appropriate to define a protocol for printing objects
"safely" for debugging purposes, and then have assert use that? I'm
thinking something along the lines of combining Common Lisp-style
print-object with Smalltalk style inspection. Maybe:
(inspect x) ; inspection equivalent of print
(str-inspect x) ; inspection equivalent of str
Both dispatching on x via a protocol.
--
/ Peter Schuller