 (defn flush [] ;stub
   nil)
 
+(def ^:private char-escapes
+  (js-obj
+    "\"" "\\\""
+    "\\" "\\\\"
+    "\b" "\\b"
+    "\f" "\\f"
+    "\n" "\\n"
+    "\r" "\\r"
+    "\t" "\\t"))
+
+(defn ^:private quote-string
+  [s]
+  (str \"
+       (.replace s (js/RegExp "[\\\\\"\b\f\n\r\t]" "g")
+         (fn [match] (aget char-escapes match)))
+       \"))
+
 (deftype StringBufferWriter [sb]
   IWriter
   (-write [_ s] (.append sb s))

  [fmt & args]
  (print (apply format fmt args)))

(def ^:private char-escapes
  (js-obj
    "\"" "\\\""
    "\\" "\\\\"
    "\b" "\\b"
    "\f" "\\f"
    "\n" "\\n"
    "\r" "\\r"
    "\t" "\\t"))

(defn ^:private quote-string
  [s]
  (str \"
       (.replace s (js/RegExp "[\\\\\"\b\f\n\r\t]" "g")
         (fn [match] (aget char-escapes match)))
       \"))

(extend-protocol IPrintWithWriter
  boolean
  (-pr-writer [bool writer opts] (-write writer (str bool)))

  number
  (-pr-writer [n writer opts] (/ 1 0) (-write writer (str n)))

  array
  (-pr-writer [a writer opts]
    (pr-sequential-writer writer pr-writer "#<Array [" ", " "]>" opts a))

  string
  (-pr-writer [obj writer opts]
    (cond
     (keyword? obj)
       (do
         (-write writer ":")
         (when-let [nspc (namespace obj)]
           (write-all writer (str nspc) "/"))
         (-write writer (name obj)))
     (symbol? obj)
       (do
         (when-let [nspc (namespace obj)]
           (write-all writer (str nspc) "/"))
         (-write writer (name obj)))
     :else (if (:readably opts)
             (-write writer (quote-string obj))
             (-write writer obj))))

  function
  (-pr-writer [this writer _]
    (write-all writer "#<" (str this) ">"))

  js/Date
  (-pr-writer [d writer _]
    (let [normalize (fn [n len]
                      (loop [ns (str n)]
                        (if (< (count ns) len)
                          (recur (str "0" ns))
                          ns)))]
      (write-all writer
        "#inst \""
        (str (.getUTCFullYear d))             "-"
        (normalize (inc (.getUTCMonth d)) 2)  "-"
        (normalize (.getUTCDate d) 2)         "T"
        (normalize (.getUTCHours d) 2)        ":"
        (normalize (.getUTCMinutes d) 2)      ":"
        (normalize (.getUTCSeconds d) 2)      "."
        (normalize (.getUTCMilliseconds d) 3) "-"
        "00:00\"")))

  LazySeq
  (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "(" " " ")" opts coll))



  ICollection
  (-conj [_ o] (list o))

  IIndexed
  (-nth
