Created
April 9, 2011 03:24
-
-
Save drlivingston/911074 to your computer and use it in GitHub Desktop.
macro for functions that bind special vars
This file contains 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 binding-non-default-fn [fn-name default-specials args & body] | |
(let [special-vars (vec (doall (map gensym default-specials)))] | |
`(defn ~fn-name | |
(~args ~@body) | |
(~(vec (concat special-vars args)) | |
(binding ~(vec (interleave default-specials special-vars)) | |
~@body))))) | |
call: | |
(binding-non-default-fn resource [*kb*] [x] | |
(create-resource *kb* (resource-ify x))) | |
expected output: | |
(defn resource | |
([x] (create-resource *kb* (resource-ify x))) | |
([*kb*64 x] (binding [*kb* *kb*64] | |
(create-resource *kb* (resource-ify x))))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment