On Tue, Oct 9, 2012 at 2:40 AM, Tassilo Horn <t...@gnu.org> wrote: > Ah, so if I change a polyfn for a type X, the new behavior will only be > available to new X instances, right?
If you change a polyfn implementation for a type X, then the new behavior will be available to all instances of X, even those created before you changed the polyfn. The new versus old instances issues only manifest when you are generating new types with the same "name" as defrecord and defprotocol do. In that case, instances created with the old version of the defrecrod and defprotocol are actually instances of a different type than instances created with the newly compiled defrecord and defprotocol types. > Well, as said, those are pretty stable, so it's no issue for me. How > about the growth of the dispatch table? Say, I recompile a namespace > containing polyfn definitions 50 times during a session, will that slow > down dispatch noticeably? Maybe you could store the current active > definition form per type, so that identical definitions for the same > type don't get added to the dispatch table? Recompiling a polyfn definition 50 times will only end up with a dispatch table of one entry. The multiple entries get added when you recompile defrecord and defprotocol. When you recompile a defrecord form 50 times you get 50 different types which is why the dispatch table grows both for polyfns and for protocols. > Oh, and here's a whishlist item: It should be possible to add a > docstring to polyfns, and maybe also other metadata (:pre, :post, :tag, > ...). tools.macro/name-with-attributes makes that pretty easy. Good point. I'll look into this. > And another question: Since defpolyfn expands into a defonce form, does > that mean that all (defpolyfn foo ...) forms have to be in the same > namespace? It looks to me that currently defining the same polyfn foo > in different namespaces bar and baz will create bar/foo and baz/foo > which have nothing to do with each other (you cannot `use` both bar and > baz). IMO, that would be an argument for splitting polyfns into a > single declaration form and many definition forms providing > implementations for several types (like defmulti and defmethod, or > defprotocol and extend). Haha a good point. I'll look into this issue. Looks like I will have to split out the definition from the extension. Should be simple enough. -- 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