Currently if you happen upon a Ref in the REPL, you don't get much
helpful information:

user=> (ref #{:a 1})
#<Ref clojure.lang....@968fda>

Improving on this is not difficult:

(defmethod print-method clojure.lang.IRef [o w]
  (.write w (format "#<%...@%x: %s>"
                    (.getSimpleName (class o))
                    (System/identityHashCode o)
                    (pr-str @o))))

Now Ref and all her cousins print their values:

user=> (agent 99)
#<ag...@458f41: 99>

The identity code is included so you can tell if it's the same object
or a different one, since the identity of reference objects matter.

user=> (let [a (atom 4)] (swap! a inc) (prn a) (swap! a + 10) (prn a))
#<a...@7ecd78: 5>
#<a...@7ecd78: 15>

This is also why the #<> format is still used, disallowing 'read' from
working on the string.

--Chouser

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to