> Stu, (or anybody) I'd like to ask about a variation on this point. How
> do you handle the case where you have a general function that works
> for every type you'd like to implement a protocol for (thus not
> technically needing to be in a protocol), but maybe 1 or 2 of the many
> types have more efficient implementations possible? Do you just suck
> it up and copy and paste the general function around? Or is there a
> better way? Maybe the new case function?

This might be a job for a more granular protocol. Take a look at how granular 
Clojure's implementation abstractions are (even prior to the introduction of 
protocols). The Java interfaces often have 0, 1, or 2 methods.
 
> After reading the docs on clojure.org/protocols, it seemed like you
> could just define the general implementation of functions under Object
> and then define your specific implementations on the other types, but
> this didn't seem to work for me. I would get an error to the effect of
> "foo is not defined for Type"

Once you define a protocol for a type, you have to implement everything (that 
you plan to call) with that type. You can either (a) make more granular 
protocols, in particular single-method protocols, or (b) use the "base-map + 
assoc in overrides" pattern referenced earlier in this thread and described at 
http://fulldisclojure.blogspot.com/2010/08/thoughts-on-protocols.html.

Stu

-- 
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

Reply via email to