Skip to content

Instantly share code, notes, and snippets.

@raek
Forked from anonymous/my-macro.clj
Created January 20, 2011 09:29
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 raek/787632 to your computer and use it in GitHub Desktop.
Save raek/787632 to your computer and use it in GitHub Desktop.
(defmacro create-object [name props funcs]
(let [m (reduce #(conj %1 [%2 nil]) {} props)
d (symbol (str "dispatcher-" name))
msg-sym (gensym "msg")
params-sym (gensym "params")]
`(defn ~d [~msg-sym &~params-sym]
(cond
~@(for [f funcs]
[(= ~msg-sym ~(first f))
(apply ~(second f) ~m ~params-sym)])))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment