Until recently I was using the following snippet for writing a map on a
file...basically I was using spit/slurp. Nothing easier
(defn data->string
"Writes the object b on a file f on disk as a string."
[b fname]
(io! (spit fname b)))
(defn string->data
"Read the file f back on memory safely (#= forbidden). Contents of f
should be a clojure data-structure."
[fname]
(io!
(binding [*read-eval* false]
(read-string (slurp fname)))))
However apparently this is not the way to go....one has to use 'pr' if
it is not intended for humans to read, right?
(defn data->string
"Writes the clojure data-structure b on a file f on disk as a string."
[b f]
(io!
(with-open [w (clojure.java.io/writer f)]
(binding [*out* w *print-dup* true]
(pr b)))))
what to do though, if I want to keep *read-eval* bound to false when
reading back? Printing using 'pr' does not emit literals but their ctor
funtions instead...I do not want to give to the 'user' the ability to
pass in arbitrary code...just clojure maps, vectors, lists etc.
what am I missing? the orginal slurp/spit approach works just fine and
it doesn't allow #=, exxactly how I want it. Why is it wrong?
thanks in advance...
Jim
--
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