Skip to content

Instantly share code, notes, and snippets.

@sritchie
Created December 6, 2013 01:54
Show Gist options
  • Save sritchie/7817348 to your computer and use it in GitHub Desktop.
Save sritchie/7817348 to your computer and use it in GitHub Desktop.
(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