Never had time to play with edn and custom readers but they are funny :)
Use *print-dup* if you need to... just know how to custom read it :
user=> (edn/read-string {:readers {'user.Foo map->Foo}} "#user.Foo{:a 1
:b 2 :c 3}")
#user.Foo{:a 1, :b 2, :c 3}
user=> (edn/read-string {:readers {'user.Foo #(apply ->Foo %)}}
"#user.Foo[1, 2, 3]")
#user.Foo{:a 1, :b 2, :c 3}
Nice
Le mercredi 21 août 2013 22:33:00 UTC+2, kawas a écrit :
>
> By the way *print-dup* is the problem, maybe you should not use it :)
>
> Spot the difference :
> user=> (binding [*print-dup* true] (prn (->Foo 1 2 3)))
> #user.Foo[1, 2, 3]
>
> user=> (binding [*print-dup* false] (prn (->Foo 1 2 3)))
> #user.Foo{:a 1, :b 2, :c 3}
>
> cheers
>
> Le mercredi 21 août 2013 19:55:59 UTC+2, Jim foo.bar a écrit :
>>
>> Hi everyone,
>>
>> I am trying to serialise a record with edn. I think I am using all the
>> good practices but I get a weird error...I am using these simple functions:
>>
>> (defn data->string
>> "Writes the object b on a file f on disk as a string."
>> [b f]
>> (io!
>> (with-open [w (clojure.java.io/writer f)]
>> (binding [*print-dup* true
>> *out* w] (prn b)))))
>>
>> (defn string->data
>> "Read the file f back on memory safely. Contents of f should be a clojure
>> data-structure."
>> [f]
>> (io!
>> (edn/read-string (slurp f))))
>>
>> and I am getting this error:
>> *
>> **RuntimeException No dispatch macro for: =
>> clojure.lang.Util.runtimeException (Util.java:219)*
>>
>> Out of curiosity I tried something simpler like this:
>>
>> Clondie24.games.chess=> (defrecord FOO [a b c])
>> Clondie24.games.chess.FOO
>> Clondie24.games.chess=> (ut/data->string (FOO. :a :b :C) "FOO")
>> nil
>> Clondie24.games.chess=> (ut/string->data "FOO")
>>
>> RuntimeException No reader function for tag Clondie24.games.chess.FOO
>> clojure.lang.EdnReader$TaggedReader.readTagged (EdnReader.java:739)
>>
>>
>> What I am I missing? any suggestions?
>>
>> Jim
>>
>>
>>
>
--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
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
---
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.