On Thu, Nov 4, 2010 at 10:17 PM, ka <[email protected]> wrote:
> > May I ask a heretic question: Why don't you specify the contract in the
> docstring of the protocol?
>
> (defprotocol Coolness
> "Yadddayaddablablablubber.
> Cool things have to be Comparable and Serializable."
> (x .. "Since 'this' is cool i assume it is Serializable and
> Comparable and so logically I can safely do this cool x thing!")
> (y ...))
>
This would be a terrible protocol - protocols do not compose in this manner.
> static public ISeq seq(Object coll){
> if(coll instanceof ASeq)
> return (ASeq) coll;
> else if(coll instanceof LazySeq)
> return ((LazySeq) coll).seq();
> else
> return seqFrom(coll);
> }
>
> Do you see the above seq method as a design problem? - or if you don't
> care about Java, consider clojure.walk.
>
You can't fix Java so I'm not sure that's a legitimate example. clojure.walk
suffers from the "closed" property.
> If I understand you correctly (probability of which is less) you don't
> really see protocols as defining abstractions - but just as a
> convenient tool for polymorphism. Like:
>
polymorphism *is* a form of abstraction.
> I simply asked - is there anything fundamentally wrong with the notion
> of those protocols being composable. Protocol P is a set of abstract
> functions, can we have a convenient way of saying P = union(P1, P2) ?
>
This is desirable, but it's not clear whether this should be a feature of
protocols themselves.
> On a related note how is this:
>
> (defn dispatch-fn [this ..]
> (if (and (comparable? this) (serializable? this))
> :green-signal :red-signal)
>
Aha! Getting warmer.
This highlights a sore spot in the current multimethod implementation - the
dispatch fn is "closed". Rich has expressed several times that he would like
to see a predicate dispatch implementation for clojure that removes this
wart.
David
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en