Easy way to work with text without having to escape quotes in Clojure?

I play with text parsing in REPL, and sometimes I want to dump a bunch of data into a string, whether it be a bibtex record or some kind of EBNF notation, etc. Typically, there may be quotation marks in a string, and this is very tedious and error prone to manually avoid them.

Is there an alternative way to do this, for example Ruby %Q|Ican use "Quotation Marks"|or heredocs, etc.? Or could you write a macro or reader modification to enable this?

+5
source share
2 answers

There was a discussion about stronger syntax quoting, but no changes to support this are expected.

, REPL, , . , , , REPL - read-line :

(defn read-lines []
  (->> (repeatedly read-line)
       (take-while #(not= % "."))
       (mapcat #(list % "\n"))
       (apply str)))

, (read-lines) REPL, , . :

user=> (read-lines)
  #_=> This "works"
  #_=> sometimes...
  #_=> .
"This \"works\"\nsometimes...\n"
user=> (print *1)
This "works"
sometimes...
nil
0

, , slup? , , ?

(slurp "tempfile.txt")

(def data (slurp "tempfile.txt"))

(defn rd [] (def data (slurp "tempfile.txt")))
-1

All Articles