I'm a relative newcomer to Clojure, and I'm puzzled by problems I have
using extend in a webapp. Any help would be hugely appreciated.
My use case is basically this:
(defrecord FooRecord [msg])
(defprotocol FooProtocol
(bar [foo] "to use with extend-type"))
(extend FooRecord
FooProtocol
lein-ring uses AOT compilation to build war files. AOT compilation in
clojure is, well, problematic sometimes. Fortunately it can almost always
be avoided using clever indirection.
For example: https://github.com/pdenhaan/extend-test/pull/1 builds a war
that works =)
I've got a pull open against
TL;DR: If you wait for that lein-ring pull to get merged, you can upgrade
lein-ring and your problem will go away. If you wait for Clojure 1.7.0 it's
possible your problem will go away, though I'm less confident here (the
current alpha doesn't have a fix). If you want your problem to go away
*right
On further investigation, it looks like you're suffering from
http://dev.clojure.org/jira/browse/CLJ-979 -- if I apply the patch for this
bug to clojure and recompile your project everything works fine. It looks
like this patch *is* slated to make it into Clojure 1.7.0, so that should
also make you
Btw, if you own the defrecord, extend a protocol to it directly in its
definition, rather than in a separate extend or extend-protocol form.
Doing it inline makes the record implement the protocol's backing
interface, which will be much more efficient. (If it's not your record you
don't really
Those are some very comprehensive responses indeed; thanks Michael. It
makes sense now. I'll keep an eye on lein-ring and clojure upgrades and in
the mean time work around it.
Ghadi, you are of course right; thanks. I was playing around with extend so
two types could share an implementation wit