6

I'm trying to parse a nested structure of PriorityMaps:

(def reader-map
 {
   'util/pm (fn [x] (println "reading > " x) (parse-map x))
})

(binding [*data-readers* reader-map]
    (clojure.core/read-string "#util/pm \"{:z 4 :y #util/pm \"{:y 3 :x 3}\" :x 9}\""))

...but I don't see the nested string passed into my handler as I'd expect, only the string up to the first nested tag:

 reading >  {:z 4 :y #er.util.net/pm

what am doing wrong ?

1 Answer 1

5

You need more backslashes if you want nested quotes:

(binding [*data-readers* reader-map]
    (clojure.core/read-string "#util/pm \"{:z 4 :y #util/pm \\\"{:y 3 :x 3}\\\" :x 9}\""))
6
  • oh god so exponential levels of escaping ?
    – Hendekagon
    Oct 9, 2012 at 3:43
  • 1
    Yup, exponential backslash expansion! I really hope you weren't planning on nesting too many levels.
    – DaoWen
    Oct 9, 2012 at 5:46
  • 1
    I was - am going to use another method now! Store as normal maps, post-process into PriorityMaps.
    – Hendekagon
    Oct 9, 2012 at 6:15
  • 3
    @Hendekagon the value associated with a tag doesn't have to be a string; it can be any normally readable Clojure data structure. Something like "#util/pm {:z 4 :y #util/pm {:y 3 :x 3}}" can work, AFAIK. Oct 9, 2012 at 6:31
  • 1
    @JoostDiepenmaat, the documentation agrees with you. Looks like he'd just have to change the reader to accept a map rather than a string.
    – DaoWen
    Oct 9, 2012 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.