Alternate string quote syntaxes
Motivation
- doc strings with examples could be more human readable
XML, JSON or SQL generation tests become filled with escaped quotes
- pasting JSON into a string, which could then easily have `read-json` called on it
Possible Solutions
Python-like triple quoted strings
Pros:
- relatively simple syntax, for humans and parsers
Cons:
- minor breaking change - """""" which is 3 empty strings would now be interpreted as only one empty string
- have to add reader macro
- breaking change to every other tool that reads Clojure syntax
- including regexp-based syntax colorers, etc.
Heredocs
Pros: slightly more flexible than triple-quotes
Cons: more complex syntax
String Interpolation / Templating
Pros:
Cons:
Puzzles:
- is the built-in format function enough?
Resource files
Pros:
- Already exists
Cons:
- Separate file for each string
- Can't use for macro-interpreted things like doc strings
- In tests, having the test data separate from the test itself is hard to read
Labels:
4 Comments
Hide/Show CommentsDec 21, 2011
Joe Gallo
Regarding resource files, you can have more than one string per file – consider ordinary java properties files, which are easy enough to work with (and powerful, when the string values contained therein are filled with $... placeholders for format calls). http://en.wikipedia.org/wiki/.properties
Dec 21, 2011
Chas Emerick
Re: interpolation, there's this, which is in
clojure.core.strintin core.incubator.Mar 22, 2013
Steve Miner
A triple-quote reader was implemented here:
https://github.com/hozumi/clojure/commit/4707bb37c6e281a63c6916f7505fb8ee170a4695
Mar 22, 2013
Steve Miner
As of Clojure 1.5, we should consider EDN compatibility when proposing an extension to the Clojure reader. See http://edn-format.org. Also, note that Clojure 1.5 added clojure.edn/read and read-string. As a practical matter, any new string reader syntax should probably be part of EDN as well as Clojure.