Below you will find pages that utilize the taxonomy term “Clojure”
Posts
read more
Fun with Clojure Macros
It all started innocently enough. I had a deftype that was
implementing several protocols. I had written all of the protocol
functions inside the body of the deftype. And even though each
function, by itself, wasn’t overly large, the entire blob of code was
getting out of hand.
Here is a tiny little example with some made-up protocols and a type
that embedded the protocol implementation inside the deftype. In
the actual code there were many more methods that needed to be
implemented.
(defprotocol Proto1
(p11 [this])
(p12 [this foo bar]))
(defprotocol Proto2
(p21 [this])
(p22 [this baz bin]))
(deftype MyType [item1 item2 item3 item4]
Proto1
(p11 [this] ...)
(p12 [this foo bar] ...)
Proto2
(p21 [this] ...)
(p22 [this baz bin] ...))