在Clojure 1.5.0中,如何爲我自己的記錄類型(使用defrecord定義)提供自定義漂亮打印機。漂亮 - 使用Clojure中的自定義方法打印記錄
(defrecord MyRecord [a b])
(defmethod print-method MyRecord [x ^java.io.Writer writer]
(print-method (:a x) writer))
(defmethod print-dup MyRecord [x ^java.io.Writer writer]
(print-dup (:a x) writer))
(println (MyRecord. 'a 'b)) ;; a -- OK
(clojure.pprint/pprint (MyRecord. 'a 'b)) ;; {:a a, :b b} -- not OK, I want a
我想clojure.pprint/pprint
也使用我的打印機cutsom(現在,應該只是漂亮的版畫無論是在外地插圖的記錄a
)。
就要離開這個在這裏,因爲這就是我爲什麼來到這裏:在'pprint-myrecord'功能應該寫爲'*出*',而不是返回一個字符串。 – pascal 2014-05-04 20:51:15