Skip to content

Instantly share code, notes, and snippets.

@bnyeggen
Created April 10, 2012 01:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bnyeggen/2347883 to your computer and use it in GitHub Desktop.
Save bnyeggen/2347883 to your computer and use it in GitHub Desktop.
More interning with Clojure
(defmacro with-interns
"interns => [intern1 intern2...]
Evaluates body while making available many functions, bound to the
symbols in interns. Each fn, when called, returns a deduped reference to
its argument. The deduplication is with respect to any previously-called
arguments to that fn.
(with-interns [intern]
(into {}
(for [k (range 100000)]
[k (intern (vec (repeatedly 3 #(rand-int 10))))])))"
[interns & body]
(cond (= (count interns) 0)
`(do ~@body)
(symbol? (interns 0))
`(let [intern# (atom #{})
~(interns 0) #(get @intern# % (get (swap! intern# conj %) %))]
(with-interns ~(subvec interns 1) ~@body))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment