I'm working on some complex analysis where it takes about twelve hours to 
construct the model to be analysed. Once it's constructed I'm doing various 
interactive things to explore it, but I can't currently persist it in a 
form in which it can be read back in, so that when the REPL session ends it 
is lost and I need to run the construction process again.

When I was creating the system I had thought, airily, 'well, Clojure is 
Lisp so all I need to do is spit the structure out to a file and slurp it 
back in again'. Unfortunately, of course, Clojure is only mostly Lisp.

My problem is clj-time objects, both date-time and interval. These are 
essentially Joda time objects, and when they are printed, what you get is a 
string representation of an object reference. When the reader reads it 
back, what you have is a string:

user=> (def foo (tc/now))

#'user/foo

user=> (spit "/tmp/saved-time" (with-out-str (pr foo)))

nil

user=> (def bar (slurp "/tmp/saved-time"))

#'user/bar

user=> (= foo bar)

false

user=> (type foo)

org.joda.time.DateTime

user=> (type bar)

java.lang.String


So, my question: in this particular case, what is the simplest means of 
writing my data structures (which, apart from the clj-time objects, 
comprises deeply nested maps of keywords, strings and numbers - all things 
which the Clojure reader and writer can cope with) to disk in a form in 
which they can subsequently be read back?


There are two obvious solutions: one is to have a function which walks the 
data structure and returns an equivalent data structure in which each 
clj-time object is replaced by a function invocation which when invoked 
creates an equivalent clj-time object; the other is to use Java 
serialisation to serialise the whole structure as in the answer to this 
stackoverflow question 
<http://stackoverflow.com/questions/7701634/efficient-binary-serialization-for-clojure-java>
.


Which of these would people go for? Or is there some other solution I have 
not thought of?

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to