On Tue, Dec 2, 2008 at 3:52 PM, Mark Volkmann <[EMAIL PROTECTED]> wrote:
>
> (def my-string (print-dup [1 2 3]))
> (def my-data (read my-string))
>
> Can you give a simple example of serializing and deserializing a
> Clojure collection?

For "serializing" you have a couple options:
(def my-string (binding [*print-dup* true] (pr-str [1 2 3])))
(def my-string (with-out-str (print-dup [1 2 3] *out*)))

I don't know which is "better".  Both produce a my-string like:
"#=(clojure.lang.LazilyPersistentVector/create [1 2 3])"


The regular 'read' function can read these *print-dup* strings to
reproduce the original structure, a.k.a. deserialize:

(def my-data (with-in-str my-string (read)))

--Chouser

--~--~---------~--~----~------------~-------~--~----~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to