Skip to content

Instantly share code, notes, and snippets.

@maxcountryman
Created April 28, 2014 16:04
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 maxcountryman/11376431 to your computer and use it in GitHub Desktop.
Save maxcountryman/11376431 to your computer and use it in GitHub Desktop.
(defmacro loop-vars
"Like loop, but will automatically populate recur points where the special
var recur-> is found.
Mostly useful in mutable contexts, where some external factor causes the
recur bindings to change.
"
[bindings & body]
{:pre [(and (vector? bindings)
(even? (count bindings)))]}
`(loop ~bindings
~@(walk/postwalk
(fn find-recur-> [x]
(if (= x 'recur->)
`(recur ~@(map second (partition 2 bindings)))
x))
body)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment