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 (slurp fname))] (struct db fname object)) (catch Exception e (println (format "Caught exception when reading file %s:\n%s" fname e))))) When writing it first writes to a temporary file and then renames so that if the power cuts in the middle that you won't be left with a half file :) On Tue, Jan 26, 2010 at 7:22 AM, jleehurt <jleeh...@gmail.com> wrote: > 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 the error > "java.lang.IllegalArgumentException: No matching method found: create > (NO_SOURCE_FILE:0)" when I run it in the REPL: > > (import > '(java.io StringReader PushbackReader)) > > (defstruct Y :a :b) > (def y (struct Y "a" "b")) > > (defn serialize [x] > (binding [*print-dup* true] (pr-str x))) > > (defn deserialize [x] > (let [r (new PushbackReader (new StringReader x))] > (read r))) > > (deserialize (serialize y)) > > > What am I doing wrong here? > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with your > first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > -- Anders Rune Jensen http://www.iola.dk -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en