Skip to content

Instantly share code, notes, and snippets.

@amalloy
Forked from anonymous/gist:1590658
Created January 10, 2012 19:47
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 amalloy/1590781 to your computer and use it in GitHub Desktop.
Save amalloy/1590781 to your computer and use it in GitHub Desktop.
ugly macro
(defmacro defcontroller [name & actions]
(let [iname (symbol (str "I" name))]
`(do
(defprotocol ~iname
~@(for [[m as & fs] actions]
`(~m [~@as])))
(deftype ~name []
~iname
~@(for [[m as & fs] actions]
`(~(with-meta m {:tag "test"}) [~'this ~@as] ~@fs))))))
user> (set! *print-meta* true)
true
user> (macroexpand-1 '(defcontroller Foo (x [a] (inc a))))
(do (defprotocol IFoo (x [a]))
(deftype Foo [] IFoo
(^"test" x [this a] ^{:line 1} (inc a))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment