Skip to content

Instantly share code, notes, and snippets.

@rplevy
Created April 24, 2012 17:25
Show Gist options
  • Save rplevy/2481715 to your computer and use it in GitHub Desktop.
Save rplevy/2481715 to your computer and use it in GitHub Desktop.
string that can contain quotes (for reader-valid content only)
(defmacro qq [& body]
`(->>
(map (fn [s#]
(if (string? s#)
(format "\"%s\"" s#) (str s#)))
(quote ~body))
(interpose " ")
(apply str)))
(defn myfn "docstring \"the normal way\" sort of a pain" [] )
(defn ^{:doc (qq this docstring is "a little better")} myfn2 [] )
;; and you can interpolate values
(qq this string is #=(+ 1 1) times "better")
@AlexBaranosky
Copy link

Yep. Have you seen Chas Emerick's string interpolation macro? ... I don't have a link handy.

@rplevy-draker
Copy link

Yeah, that is pretty nice. Interpolation wasn't my main aim with what I was playing with here but it is an added plus that you get for free.

@rplevy-draker
Copy link

Actually I just realized the interpolation is not really what it seems, because you mostly won't have the values you want at read time.

Fail:

(let [x 1](qq this string is #=%28+ x x%29 times))

@rplevy-draker
Copy link

But it could be explicitly supported similar to Chas's macro...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment