Someone correct me if I'm wrong, but I think what's happening is that when you call (defprotocol Foo ...) for the second time, you're setting the symbol Foo to point to the new protocol, while the original fooed still has the old protocol. It also binds bar to a completely new function, which has only been set to work with the new protocol so far. So the old bar, if it still existed, would work fine with the old fooed, but the new bar has nothing set for dealing with the old protocol. I think that if you took out the second defprotocol it would work fine.
On Aug 25, 11:55 am, DeverLite <derby.lit...@gmail.com> wrote: > So if I do this in a clean REPL > > Clojure 1.2.0 > user=> (defprotocol Foo (bar [this x])) > Foo > user=> (defrecord fooed [] Foo (bar [this x] (* 2 x))) > user.fooed > user=> (defprotocol Foo (bar [this x])) > Foo > user=> (extend-type Object Foo (bar [this x] (/ 2 x))) > nil > user=> (def fooey (fooed.)) > #'user/fooey > user=> (bar fooey 10) > 1/5 > user=> (defrecord fooed [] Foo (bar [this x] (* 2 x))) > user.fooed > user=> (def fooey (fooed.)) > #'user/fooey > user=> (bar fooey 10) > 20 > > I would have expected 20 the first call to bar to be 20. > > This is a natural sequence of lines to execute if you---for > instance--- have Foo defined in file A and fooed in file B, and you > then add a default implementation using extend-type in file A and then > recompile file A. > > This scenario is easily fixed by recompiling file B (as the last few > lines demonstrate). > > I don't see any easy way to actually fix this behavior (though my > understanding of how protocols are implemented is largely based on > seeing how they behave and my limited knowledge of the JVM, rather > than actually looking at the code), but it does seem like it would be > less surprising if it could be accomplished. > > Thoughts? Should I post this as a ticket in assembla? -- 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