I have a simple structure like this:
(def example {:bbb "bbb" :xxx [1 2 3] :yyy '(3 5 7)})
If I write this out to a file it contains
{:bbb "bbb" :xxx [1 2 3] :yyy (3 5 7)}
Which is mostly correct, but if I load-file on this, it fails because it tries to treat 3 as a function (the parens are no longer quoted, so tries to evaluate as a function).
What is the right way to do this? Thanks!
If you want to read back a Clojure datum previously written to a file as a literal, you need to use
readorread-stringrather thanload-file:You can call
readmultiple times to read successive forms (as long as you hold theReaderopen, of course).This involves no evaluation except when the
#=reader macro occurs in the input stream, in which case the form immediately following it is evaluated at read time and replaced with the result inread‘s output (e.g.(read-string "#=(+ 1 2)")returns3). To prohibit evaluation of#=prefixed forms bind*read-eval*tofalse.