Perhaps I should have explained why I think 20 should be the right answer. This is based on my expectation that once I've compiled a file the behavior of records or types defined in that file will not change (unless I re-bind functions called by the record or type). The above behavior violates this principle in a very natural use case where I add or recompile a default implementation of a protocol located in a separate file from a record implementing that protocol.
On a more practical level the current behavior means I have to explicitly recompile multiple files when I change a line in one file, which is somewhat inconvenient (perhaps there should be a way to auto- detect this situation and have the Clojure compiler recompile the appropriate file???). If I forget to do this then the code will behave in unpredictable ways because I've suddenly replaced the non-default implementations with a new default implementation. On Aug 26, 7:08 am, MikeM <michael.messini...@invista.com> wrote: > I may have misunderstood what I've read about protocols, so please set > me straight if the following is wrong - > > On Aug 25, 11:08 pm, Stuart Halloway <stuart.hallo...@gmail.com> > wrote:> I think the current behavior follows the principle of least surprise: > > > (1) bar is a function, in whatever namespace the protocol Foo is defined in > > But bar is not a single function. Multiple bars can coexist in some > sense, right? Otherwise there's no polymorphism? > > > (2) you redefine bar (perhaps by reloading the file Foo is in) > > I don't see this as bar being re-defined, rather bar is defined for > fooed, then defined for Object > > > (3) you call bar and get the new behavior > > It seems that the dispatch mechanism for bar is preferring Object's > bar rather than user.fooed's bar. This is not what I expected. So > maybe the right way to think about this is that protocols don't pay > attention to class hierarchy when dispatching: user.fooed is an > Object, and bar was defined for Object after bar was defined for > user.fooed, so Object's bar is selected? -- 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