Skip to end of metadata
Go to start of metadata

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:
  1. Dec 21, 2011

    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

  2. Dec 21, 2011

    Re: interpolation, there's this, which is in clojure.core.strint in core.incubator.

  3. Mar 22, 2013

    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.