1.3.0 permalink Arrow_down_16x16

print-dup

clojure.core

2 Examples top

  • ;; print-dup can be used for basic serialization
    ;; the following methods write/read clojure forms to/from a file
    
    (defn to-file
      "Save a clojure form to a file"
      [#^java.io.File file form]
      (with-open [w (java.io.FileWriter. file)]
        (print-dup form w)))
     
    (defn from-file
      "Load a clojure form from file."
      [#^java.io.File file]
      (with-open [r (java.io.PushbackReader. (java.io.FileReader. file))]
         (read r)))
  • ;; print-dup is a multimethod, you can extend it to support new types.
    ;; The following statement adds print-dup support to 
    ;; the java.util.Date class
    (defmethod print-dup java.util.Date [o w]
      (print-ctor o (fn [o w] (print-dup (.getTime  o) w)) w)) 
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:3256 top

(defmulti print-dup (fn [x writer] (class x)))
Vars in clojure.core/print-dup:
Used in 0 other vars

Comments top

No comments for print-dup. Log in to add a comment.