Skip to content

Instantly share code, notes, and snippets.

@chrisschreiner
Created March 30, 2010 01:14
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 chrisschreiner/348639 to your computer and use it in GitHub Desktop.
Save chrisschreiner/348639 to your computer and use it in GitHub Desktop.
(use 'clojure.walk)
(defmacro with-iota [& body]
"Provides the local 'iota' which starts at 0 and automatically self-increments"
(let [iota (gensym "whatever-")]
`(let [~iota ~(atom -1)]
~@(map #(postwalk-replace {'iota `(swap! ~iota inc)} %) body))))
(with-iota
(let [a iota
b iota
c iota]
(apply println [a b c])))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment