On Aug 12, 10:51 pm, Stuart Halloway <stuart.hallo...@gmail.com>
wrote:
> The other thing that you should consider is that protocols are the
> contract for implementers, not the contract for callers. If you
> change a contract for implementers, then the implementers *must*
> change.
>
> Take your example of a function that has a reasonable default for
> any object. Often such a function does not need to be part of the
> contract for implementers (i.e. the protocol) at all.
>
> To make this more concrete, look at how protocols are used in
> Clojure itself. InternalReduce is a contract for implementers,
> consumers call reduce.  Ditto for IOFactory: clients don't call it,
> they call the functions reader, writer, etc. instead.

Stuart, I just watched your presentation on Clojure 1.2 protocols at
http://vimeo.com/11236603. Thanks for such a clear and informative
presentation -- it was especially illuminating to be shown how
InternalReduce is used.

I certainly take your point that you generally will require
implementors to provide all methods of a protocol -- because if you
can provide a default, why are you asking clients to provide it in the
protocol?

However, in my last message I have an example of where an extension to
the protocol of an optional method that is there for performance: it
*can* be implemented slowly by default, but new clients might want to
provide a faster version. It's kind of the same situation as
InternalReduce: you can always reduce by treating the item as a seq
(using the InternalReduce implementation for clojure.lang.ISeq), but
InternalReduce can be re-implemented for specific types like
java.lang.String as an optional accelerator.

A new method can always be implemented on a new protocol, and a
default provided for Object, but I guess I'm looking for the best of
both worlds.

In looking for examples in Java and COM of interface evolution, the
instances that immediately come up are actually examples where
implementors really do need to provide all methods,
e.g. LayoutManager, LayoutManager2 (AWT), IProvideClassInfo,
IProvideClassInfo2 (COM). So perhaps what I'm really asking for is
better seen as an equivalent to a :default multimethod.

Matthew.

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