Created
August 6, 2015 11:39
-
-
Save ChrisBlom/7e2766671079cf9263f4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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