We are having a few issues with records and protocols in different namespaces.
We have a protocol in namespace foo.proto.
(ns foo.proto)
(defprotocol Proto
(do-stuff [this x y]))
I have a record RecordA in namespace foo.record:
(ns foo.record
(:require [foo.proto :as proto]))
(defrecord RecordA [bar])
;; RecordA implements the protocol:
(extend-type RecordA
proto/Proto
(do-stuff [this x y] (* x y (:bar this))))
This works fine as long as we are in the repl. Now if we on the otherhand make an uberjar and run the code we get:
No implementation of method: :do-stuff of protocol: #'foo.proto/Proto found for class
If we on the other hand implement the protocol in the type declaration like so:
(defrecord RecordA [bar]
proto/Proto
(do-stuff [this x y] (* x y (:bar this))))
We no longer get the error (which took some time to figure out). Also if we move the declaration of Proto into the same ns as RecordA we do not get the error either.
My questions:
What is the difference between implementing in the declaration and in extend-type or extend-protocol?
Why would it work if we move the Record and Protocol declarations into the same ns?
Thanks