Created
December 6, 2013 01:54
-
-
Save sritchie/7817348 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 defactions | |
"Takes a list of function symbols and defines atom-swapping versions of each." | |
[& syms] | |
`(do ~@(for [sym syms | |
:let [bang (-> (name sym) (str "!") symbol)]] | |
`(def ~(with-meta bang | |
{:arglists (->> (resolve sym) meta :arglists | |
(map (fn [xs] (into ['state-atom] xs))) | |
(cons 'quote))}) | |
(fn [state# & args#] | |
(apply swap! state# ~sym args#)))))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment