Skip to content

Instantly share code, notes, and snippets.

@alandipert
Created March 30, 2010 04:11
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 alandipert/348741 to your computer and use it in GitHub Desktop.
Save alandipert/348741 to your computer and use it in GitHub Desktop.
(use 'clojure.walk)
(defmacro using-iota [& body]
(let [iota (gensym "iota")
forms (map #(postwalk-replace {'iota `(swap! ~iota inc)} %) body)]
`(let [~iota (atom -1)]
~@forms)))
(using-iota
(let [c0 iota
c1 iota
c2 iota]
;; [c0,c1,c2] = [0,1,2]
(println c0 c1 c2)))
(using-iota
(let [a (bit-shift-left 1 iota)
b (bit-shift-left 1 iota)
c (bit-shift-left 1 iota)]
;; [a,b,c] = [1,2,4]
(println a b c)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment