Skip to content

Instantly share code, notes, and snippets.

@drlivingston
Created April 9, 2011 03:24
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 drlivingston/911074 to your computer and use it in GitHub Desktop.
Save drlivingston/911074 to your computer and use it in GitHub Desktop.
macro for functions that bind special vars
(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