Skip to content

Instantly share code, notes, and snippets.

@luxbock
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save luxbock/8784c3b80111825802e2 to your computer and use it in GitHub Desktop.
Save luxbock/8784c3b80111825802e2 to your computer and use it in GitHub Desktop.
;; trying to turn a map like {"increment" #(inc %)} => (def increment #(inc %))
(defn named-fn [[name f]] `(def ~(symbol name) ~f))
(defmacro fns-from-map [m]
(eval ``(do ~@(map named-fn ~m))))
user> (def test-map {"incrementor" #(inc %)
"decrementor" #(dec %)})
#'user/test-map
user> (fns-from-map test-map)
#'user/decrementor
user> (incrementor 5)
6
user>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment