(do
(def s1 """{ "fruit": "apple", "color": "red" }""")
(def s2 """
{
"fruit": "apple",
"color": "red"
}
""")
(println s1)
(println s2))
Interpolation is controlled using ~{}
and ~()
forms. The former is
used for simple value replacement while the latter can be used to
embed the results of arbitrary function invocation into the produced
string.
Interpolation is implemented as a reader macro. It's parsed at read
time and turned into a (str args)
expression.
(do
(let [x 100]
(println "x: ~{x}")
(println "f(x): ~(inc x)")))
(do
(let [x 100]
(println """x: ~{x}""")
(println """f(x): ~(inc x)""")))