Python has a notation for "raw strings"
I'm working on a project right now where the lack of raw strings is killing me.
Given the new work on edn and clojure.tools.reader, I'm hoping that the reader technology is now at a point where adding raw strings would be a trivial endeavor, thus tipping the value:complexity ratio of adding raw strings in favor of doing it.
One of Clojure's value propositions is that it is good for making DSLs.
The reality is that Clojure is mostly only good for writing DSLs that use Clojure's syntax.
Sometimes a string-based DSL is exactly what you need to achieve the desired clarity.
Reading a raw string stored in a file is already trivial :)
I belive that data is the ultimate DSL anyway - it allows one to express arbitrarily specific information in an extensible way. Interleaving code and data (as some languages' DSL facilities foster) is inherently complex (and limited).
I find raw string handling in XML simply ugly :)
Do you have a suggestion on how to represent raw strings ? Something concrete
we could discuss about ?
Nobody wants to store every regexp in a separate file.
Some DSLs are based on a really handy notation that has been in use by computer scientists and/or mathematicians for decades or longer. Trying to shoe-horn these convenient notations into something that looks like Clojure is not always the right way to go.
Nobody wants to store every regexp in a separate file.
That's because regexes are 'atomic' - you don't place Clojure expressions in the middle of them. SQL or math are vastly different from that. As for SQL, it *is* common practice to store them as isolatedly as possible.
(defn ^{:examples '[(with-out-str (clipboard (doc distinct)))]
clipboard [x] ...)
Just if a mechanism like this were used more widely... we'd get syntax coloring for free, and a facility for programatically querying examples.
XML, JSON or SQL generation tests become filled with escaped quotes
Dynamic regex building is a standard technique. Unfortunately, once you leave the regex literal world, you are back to escaping everything.
this works pretty well, at least better than I expected, e.g.:
user=> (def r1 #"(\s.)")
#'user/r1
user=> (def r2 #"([abc])")
#'user/r2
user=> (def r3 (re-pattern (str r1 "|" r2)))
#'user/r3
user=> r3
#"(\s.)|([abc])"
user=> (re-find r3 " x")
[" x" " x" nil]
user=> (re-find r3 "b")
["b" nil "b"]
str is based on the toString() method of java.util.regex.Pattern, so I do not understand why you say it only works if you build up from parts that are literal regexes. For example:
user=> (def r1 (re-pattern "\\sfoo|bar\\d+"))
#'user/r1
user=> (def r2 (re-pattern "taking over the world( world)*\\b"))
#'user/r2
user=> (def r3 (re-pattern (str "(" r1 ")|(" r2 ")")))
#'user/r3
user=> r3