I'm playing around with text parsing in the REPL, and sometimes want to dump in a bunch of data into a string, whether it's a bibtex entry or some EBNF notation etc. Typically there might be quotation marks in the string, and it's very tedious and error-prone to have to manually escape them..
Is there an alternative way of doing this, such as Ruby's %Q|I
can use "Quotation Marks"|
or heredocs
etc? Or would it be possible to write a macro or modification of the reader to enable this?
There has been some discussion about a more robust quoting syntax, but no changes to support this seem imminent.
In the meantime, to specifically handle the REPL interaction you mention, you might find this useful. Note it probably doesn't work for every REPL out there -- they don't all support read-line
terribly well:
(defn read-lines [] (->> (repeatedly read-line) (take-while #(not= % ".")) (mapcat #(list % "\n")) (apply str)))
Use it by running (read-lines)
at the REPL, pasting your content, and then adding a line with a .
by itself:
user=> (read-lines) #_=> This "works" #_=> sometimes... #_=> . "This \"works\"\nsometimes...\n" user=> (print *1) This "works" sometimes... nil
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With