Helping newcomers to the language on #clojure, I often find the need to use a protocol in reference to it's namespace rather than the namespace of the datatype extending it is a counter-intuitive one for people learning the language. Similar with dispatch methods.
Speculatively, I think it has to do with a bad mental model of the primary "ownership" of the method - often the method is thought of as belonging to the datatype, where it actually belongs to the multimethod / protocol interface. A good example of this in practice: people who think they need circular namespace dependencies or forward declaration in order for two records / types to interact often have a hard time realizing that if they code to a set of multimethods or a defprotocol and not a concrete datatype, the circularity / forward reference is usually trivial to eliminate. And more fundamentally that the "agency" doesn't belong to the record or type, it belongs to the method functions being called, and to abstract that away from a concrete datatype is precisely the point of these polymorphic constructs. On Monday, October 27, 2014 3:59:43 AM UTC-7, Gary Verhaegen wrote: > > As recently mentioned on another thread, this also means that you cannot > have two different protocols with the same method names in the same > namespace. This may be surprising, especially from an OO background, where > it is very natural to have two types with the same operations. > > On Monday, 27 October 2014, Sven Richter <sve...@googlemail.com > <javascript:>> wrote: > >> Hi Daniel, >> >> When running through tutorials and blog posts it did not occur to me that >> the functions of a defprotocol are namespaced to where they are defined. >> Meaning, calling these functions I have to use their original namespace. >> It is obvious when one reads the official documentation, but one does not >> always do this first, so that wsa one pitfall I ran into. >> >> Best Regards, >> Sven >> >> Am Sonntag, 26. Oktober 2014 16:48:29 UTC+1 schrieb Daniel Higginbotham: >>> >>> What's difficult when it comes to understanding multimethods, records, >>> types, and protocols? I'm writing a chapter on multimethods, records, >>> types, and protocols for the book Clojure for the Brave and True, and I'd >>> love to hear about what kinds of pitfalls I should be sure to cover :) >>> >>> Thanks! >>> Daniel >>> >> -- >> 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 >> --- >> You received this message because you are subscribed to the Google Groups >> "Clojure" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to clojure+unsubscr...@googlegroups.com. >> For more options, visit https://groups.google.com/d/optout. >> > -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.