Skip to content

Instantly share code, notes, and snippets.

@ChrisBlom
Created August 6, 2015 11:39
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 ChrisBlom/7e2766671079cf9263f4 to your computer and use it in GitHub Desktop.
Save ChrisBlom/7e2766671079cf9263f4 to your computer and use it in GitHub Desktop.
(defmacro eval-with-bindings [bindings form]
(assert (even? (count bindings)) "an even number of forms in binding vector")
(let [binding-pairs (partition 2 bindings)
args (mapv first binding-pairs)
vals (map second binding-pairs)]
`((eval (fn ~args ~form))
~@vals)))
(let [foo inc]
(eval '(foo 1)))
;;=> fails
(eval-with-bindings [foo inc] '(foo 1))
;;=> 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment