• (<< string)
Takes a single string argument and emits a str invocation that concatenates
the string data and evaluated expressions contained within that argument.
Evaluation is controlled using ~{} and ~() forms. The former is used for
simple value replacement using clojure.core/str; the latter can be used to
embed the results of arbitrary function invocation into the produced string.

Examples:
user=> (def v 30.5)
#'user/v
user=> (<< "This trial required ~{v}ml of solution.")
"This trial required 30.5ml of solution."
user=> (<< "There are ~(int v) days in November.")
"There are 30 days in November."
user=> (def m {:a [1 2 3]})
#'user/m
user=> (<< "The total for your order is $~(->> m :a (apply +)).")
"The total for your order is $6."

Note that quotes surrounding string literals within ~() forms must be
escaped.

0 Examples top

Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/contrib/strint.clj:49 top

(defmacro <<
  "Takes a single string argument and emits a str invocation that concatenates
   the string data and evaluated expressions contained within that argument.
   Evaluation is controlled using ~{} and ~() forms.  The former is used for
   simple value replacement using clojure.core/str; the latter can be used to
   embed the results of arbitrary function invocation into the produced string.

   Examples:
   user=> (def v 30.5)
   #'user/v
   user=> (<< \"This trial required ~{v}ml of solution.\")
   \"This trial required 30.5ml of solution.\"
   user=> (<< \"There are ~(int v) days in November.\")
   \"There are 30 days in November.\"
   user=> (def m {:a [1 2 3]})
   #'user/m
   user=> (<< \"The total for your order is $~(->> m :a (apply +)).\")
   \"The total for your order is $6.\"

   Note that quotes surrounding string literals within ~() forms must be
   escaped."
  [string]
  `(str ~@(interpolate string)))
Vars in clojure.contrib.strint/<<: defmacro concat list seq str
Used in 0 other vars

Comments top

No comments for <<. Log in to add a comment.