Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nathanmarz/516412 to your computer and use it in GitHub Desktop.
Save nathanmarz/516412 to your computer and use it in GitHub Desktop.
;; Source:
(defmacro binder [& body]
(let [[tobind lexpr] (split-at (dec (count body)) body)
binded (vec (mapcat (fn [e]
(if (and (list? e) (= 'bind (first e)))
[(second e) (last e)]
['_ e]
))
tobind ))]
`(let ~binded
~(first lexpr)
)))
;; Example:
(binder
(println 1)
(bind a 2)
(println a)
(bind a 3)
(println a)
(bind b 1)
(println (+ a b)))
=>
1
2
3
4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment