Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clojure nested tagged literals

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 ?

like image 288
Hendekagon Avatar asked Oct 09 '12 00:10

Hendekagon


1 Answers

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}\""))
like image 187
DaoWen Avatar answered Sep 28 '22 01:09

DaoWen