Will Roe's blog

Anaλysis Paraλysis » Archives

In my previous post on string interpolation in Clojure, I benchmarked << from core.incubator and it proved both useful and performant. But can this useful macro be used from ClojureScript? Yes.

Add core.incubator to your dependencies in project.clj of your ClojureScript project:

(defproject some-project "1.0.0-SNAPSHOT"
  :dependencies [...
                 [org.clojure/core.incubator "0.1.3"]
                 ...]

Now you can require the strint macros in your ClojureScript source (e.g. in src/cljs/app/core.cljs):

(ns app.core
  (:require-macros [clojure.core.strint :as strint]))

Now you can use the fast string interpolator thus:

(enable-console-print!)

(let [name "Ethel Smyth"
      profession "Composer"
      born 1858]
  (println
   (strint/<< "The person named ~{name} works as a ~{profession}
and was born in ~{born}")))

That’s it!