> May I ask a heretic question: Why don't you specify the contract in the > docstring of the protocol?
Yes Meikel that is exactly what I have right now. Just trying to learn and stir up a discussion here :) Most times you'll just do fine by passing 'something' to Coolness functions and expect them to work - they'll just blow up on runtime (no .compareTo) if that 'something' isn't cool. But imagine certain scary situations where that 'something' is really 'HalfCool' and still some 'Coolness' functions work (type dispatch) behind your back!. (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 ...)) (deftype ReallyCool ... Coolness .. Comparable .. Serializable) (deftype SneakyCool .. Coolness) (x (ReallyCool.)) ;yay rocket launches and reaches moon! (x (SneakyCool.)) ;rocket launches alright (no exception thrown), but blows mid air I know you might argue its a code bug and caller's problem etc. - but you just allowed a rocket to blow up. Other times it might be necessary to know if something is 'Cool': 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); } @Laurent, > * first, when I see calls to (instance?) (satisifies?), it rings a bell in my > head. "design problem". Do you see the above seq method as a design problem? - or if you don't care about Java, consider clojure.walk. 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: (extend ReallyCool clojure.contrib.json/Write-JSON {:write-json ...}) But all of this discussion is kind of bypassing my original question, Meikel you say: > A protocol comprises functions which act on data in a certain abstract way. 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) ? On a related note how is this: (defn dispatch-fn [this ..] (if (and (comparable? this) (serializable? this)) :green-signal :red-signal) (defmulti x dispatch-fn) (defmulti y dispatch-fn) (defmulti z dispatch-fn) -- 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