You're viewing version 1.2.0 of print-dup. The latest stable version of Clojure Core is 1.3.0.
1.2.0 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:2805 top

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

Comments top

1 comment(s) for print-dup.

This is a multimethod that can be implemented to define the printing of various values when *print-dup* is bound to true.

Log in to add a comment.