Suppress printing the data that the atom is holding in the REPL? (or ref, agent, ...)

The following is perfectly valid: Clojure code:

(def a (atom nil))
(def b (atom a))
(reset! a b)

      

it is even useful in situations where backlinks are required.

However, the REPL is annoying to work with this kind of thing: the REPL will try to print the contents of such links whenever you type a or b, and of course, it will quickly generate an error.

So, is there a way to control / change the printing behavior of atoms / refs / agents in Clojure? Some loop detection would be nice, but even complete suppression of split content would be really helpful.

+3


source to share


1 answer


you can say

(remove-method print-method clojure.lang.IDeref)

      

remove the special handling of resolvable objects (Atoms, Refs, etc.) from print-method

by causing them to be printed like this:



user=> (atom 3)
#<Atom clojure.lang.Atom@5a7baa77>

      

Alternatively, you can add a more specific method to suppress the printing of content of a specific reference type:

(defmethod print-method clojure.lang.Atom [a ^java.io.Writer w]
  (.write w (str "#<" a ">")))

user=> (atom 3)
#<clojure.lang.Atom@4194e059>

      

+9


source







All Articles