On May 15, 2014, at 3:35 PM, Steven Jones <ple...@gmail.com> wrote: > Thanks, edn looks like the way to go but your example is not quite > working. The issue appears to be with pr. > > (defn foo [] 'foo) > > (def data {0 foo, > 1 '[a b c]}) > > (spit filename (pr data))
Use pr-str instead of pr. It returns a string containing the text representing data. > Second despite the documentation that pr output is a readable format, > when I attempt to read it I get a runtime exception of "Unreadable form" > > > (pr foo) > --> #<core$foo edntest.core$foo@7dce092>nil > > #<core$foo edntest.core$foo@7dce092> > --> RuntimeException Unreadable form clojure.lang.Util.runtimeException > (Util.java:219) There is no built-in way to access an existing function value as readable data. Searching the google group history for serializable function yields some discussion of the issues involved. If you have access to the code for the function at the time it's being loaded into clojure (read and compiled), you can write code to capture the text of the function definition from there. This lib woks along those lines and might be useful to you: https://github.com/technomancy/serializable-fn/ You may also want to consider another representation for function values, something like registering them by name and serializing the name could work. It depends on how much control you have over the environment around serializing and deserializing and how general the capabilities of the serialized code need to be. --Steve -- 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.