Pretty-printing this map comes out pretty ugly:
{:type :move,
:name :boost,
:from
{:nodeid :plus,
:name :left-operand,
:value
{:args [:result :right-operand],
:f
#object[fargish.workspace_test$fn__159675$fn__159678 0xb3f518f "fargish.workspace_test$fn__159675$fn__159678@b3f518f"]},
:dockclass :input,
:ref [:plus :left-operand]},
:to
{:nodeid :source11,
:name :output,
:value 11,
:dockclass :output,
:ref [:source11 :output]},
:do
#object[fargish.workspace$do_boost 0x179d226e "fargish.workspace$do_boost@179d226e"],
:do-hypothetically
#object[fargish.workspace$do_hypothetical_boost 0x68d6475a "fargish.workspace$do_hypothetical_boost@68d6475a"]}
Most of the time, I don't need to see most of that. I'd like it to look something roughly like this:
#boost{:from [:plus :left-operand] :to [:source11 :output]}
Does Clojure provide a hook to let me insert code so that if the value of a map's :type
key is :move
, str
will call a function I write to generate the string?
I've looked into print-method
. If I understand it correctly, that would extend a multimethod that dispatches on the type of the argument, viz. clojure.lang.PersistentArrayMap, not the :type
of the map. AFAIK, there's no way to "forward" to the previously defined multimethod, or else I could write a print-method
for clojure.lang.PersistentArrayMap that looked at :type
and then called the generic method if its value isn't :move
.
Even just customizing pprint
would be helpful. Theoretically, pprint
is very customizable, but I haven't found documentation that explains how. This is incomplete and suggests that pprint
isn't really done.
Affecting the output of pprint
would be nice but it isn't strictly necessary. Just being able to affect str
and print
would be a great help.