The most common cause of issues like this is if you reload ns1 after loading ns2, then T2 will be implementing an "old" version of pro-1, while fun will be testing for satisfaction of the "current" version.
On Oct 15, 8:04 am, Eric in San Diego <eric.sc...@acm.org> wrote: > Hi all - > > I'm experiencing some unexpected behavior with protocols. Stripping > out extraneous details... > > ;;;;;;;;;;;;; > (ns my.ns1 > ...) > > (defprotocol pro-1 > ...) > > (deftype T1 [...] > pro-1 > ...) > > (defn fun [p] > ^{:pre [(satisfies? pro-1 p) > ] > } > ...) > ;;;;;;;;;;;;;;;; > Then in another file: > (ns my.ns2 > (:use [my.ns1])) > > (deftype T2 [...] > pro-1 > ...) > > ... > ;;;;;;;;;;;;;;;;;;;;;;;;; > Then in a third file > (ns my.ns3 > (:use > [my.ns1] > [my.ns2])) > > (defn ... > (let [x (T2. ...) > ] > ... > (fun x) > ...)) > > This throws an error saying that 'x' does not satisfy the protocol. > > Looking at the documented source of 'satisfies?', I see that this > amounts to asking > (instance? (:on-interface pro-1) x), which => false. > > (:on-interface pro-1) => my.ns1.pro_1 > > but (class x) => T2 and (supers T2) => #{my.ns1.pro_1 > java.lang.object} > > Also, just to check (instance? T2 x) => true. > > What am I not getting here? How can x be an instance of T2 and not be > an instance of one of its supers? -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en