We have several problems with records and protocols in different namespaces.
We have a protocol in the foo.proto namespace.
(ns foo.proto) (defprotocol Proto (do-stuff [this xy]))
I have a RecordA entry in the foo.record namespace:
(ns foo.record (:require [foo.proto :as proto])) (defrecord RecordA [bar]) ;; RecordA implements the protocol: (extend-type RecordA proto/Proto (do-stuff [this xy] (* xy (:bar this))))
This works great while we are in a cue. Now, if we do uberjar on the other hand and run the code:
There is no implementation of the :: do-stuff protocol method: # 'foo.proto / Proto found for class
If we, on the other hand, implement the protocol in a type declaration as follows:
(defrecord RecordA [bar] proto/Proto (do-stuff [this xy] (* xy (:bar this))))
We no longer get the error (it took some time to understand). Also, if we move the Proto declaration to the same ns as RecordA, we also wonβt get an error.
My questions:
What is the difference between the implementation in the declaration and the extension-extension or extension-protocol?
Why will this work if we move the Record and Protocol declarations to the same ns?
thanks
source share