I have a string containing a valid Clojure form. I want to replace a part of it, just like with assoc-in
, but processing the whole string as tokens.
=> (assoc-in [:a [:b :c]] [1 0] :new)
[:a [:new :c]]
=> (assoc-in [:a
[:b,, :c]] [1 0] :new)
[:a [:new :c]]
=> (string-assoc-in "[:a
[:b,, :c]]" [1 0] ":new")
"[:a
[:new,, :c]]"
I want to write string-assoc-in
. Note that its first and last arguments are strings, and it keeps the line break and the commas. Is it doable in Clojure? The closest thing I found is read
which calls clojure.lang.LispReader
, but I don't know how works.
I want to use it to read a Clojure source file and display it with some modifications, keeping the structure of the file.