我試圖用* print-dup *來允許將clojure數據寫入文件 然後再讀回來,但是,即使在這種簡單情況下,我也遇到了問題。有什麼我做錯了嗎?我需要做什麼 才能使其發揮作用?如何使用 * print-dup *在clojure中打印記錄?一個簡單的例子
Clojure 1.3.0-alpha3-SNAPSHOT
user=> (defrecord TreeNode [val left right]) ;;create the record
user.TreeNode
user=> (TreeNode. 5 nil nil)
#:user.TreeNode{:val 5, :left nil, :right nil} ;; it works just fine
user=> (binding [*print-dup* true] (prn (TreeNode. 5 nil nil))) ;; use *print-dup* to support reading in and preserving type
#=(user.TreeNode/create {:val #=(java.lang.Long. "5"), :left nil, :right nil}) ;; this is the form we need to copy paste
nil
user=> #=(user.TreeNode/create {:val #=(java.lang.Long. "5"), :left nil, :right nil}) ;;trying to copy and paste
IllegalArgumentException No matching method found: create
clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:50) ;;we have an error
user=>
在此處發生的未來版本中的記錄設計工作:http://dev.clojure.org/display/design/defrecord+improvements – 2011-01-23 14:15:02