Re: help with serializing/deserializing structs

2010-01-27 Thread Stuart Sierra
On Jan 26, 12:46 pm, jleehurt wrote: > When I try using deftype I get the following error: > java.lang.IllegalArgumentException: No method in multimethod 'print- > dup' for dispatch value: class user.Y__5 That's probably a bug. It should work when *print-dup* is false. -SS -- You received thi

Re: help with serializing/deserializing structs

2010-01-26 Thread jleehurt
Hi Stuart, When I try using deftype I get the following error: java.lang.IllegalArgumentException: No method in multimethod 'print- dup' for dispatch value: class user.Y__5 Do I have to supply my own print-dup for the new type for this to work? Here is the code: (import '(java.io StringReader

Re: help with serializing/deserializing structs

2010-01-26 Thread Stuart Sierra
On Jan 26, 11:40 am, jleehurt wrote: > Thanks Anders. I'm not sure why, but it appears that read does not > support structmaps. That is correct, read does not work with structmaps, because it doesn't know how to resolve the struct definition while reading. deftype, the replacement for structmaps

Re: help with serializing/deserializing structs

2010-01-26 Thread jleehurt
Thanks Anders. I'm not sure why, but it appears that read does not support structmaps. The following works with a hashmap: (import '(java.io StringReader PushbackReader)) (def y (hash-map :a "a" :b "b")) (defn serialize [x] (binding [*print-dup* true] (pr-str x))) (defn deserialize [x] (l

Re: help with serializing/deserializing structs

2010-01-26 Thread Anders Rune Jensen
Hello I'm using: (defstruct db :file :data) (defn write-db [db] (let [path (str (:file db) ".tmp")] (binding [*out* (java.io.FileWriter. path)] (prn (:data db))) (. (new File path) renameTo (new File (:file db) (defn read-db [fname] (try (let [object (read-string (s

help with serializing/deserializing structs

2010-01-25 Thread jleehurt
Hi all, I am writing a distributed program using Clojure. I am trying to write some code to pass structs around to different nodes on the network by serializing and deserializing strings. I do not fully understand how to use *print-dup* and read to do this. The last line of the following gives th