 (defprotocol INamed
   (-name [x])
   (-namespace [x]))
+
+;; Printing support
+
+(deftype StringBufferWriter [sb]
+  IWriter
+  (-write [_ s] (.append sb s))
+  (-flush [_] nil))
+
+(defn pr-str*
+  "Support so that collections can implement toString without
+   loading all the printing machinery."
+  [^not-native obj]
+  (let [sb (gstring/StringBuffer.)
+        writer (StringBufferWriter. sb)]
+    (-pr-writer obj writer (pr-opts))
+    (-flush writer)
+    (str sb)))
 
 ;;;;;;;;;;;;;;;;;;; symbols ;;;;;;;;;;;;;;;
 

(defn ^:export set-print-fn!
  "Set *print-fn* to f."
  [f] (set! *print-fn* f))

(def
  ^{:doc "bound in a repl thread to the most recent value printed"}

(declare TransientHashMap)

(deftype PersistentHashMap [meta cnt root ^boolean has-nil? nil-val ^:mutable __hash]
  Object
  (toString [coll]
    (pr-str* coll))

  IWithMeta
  (-with-meta [coll meta] (PersistentHashMap. meta cnt root has-nil? nil-val __hash))

