On 22 Mar 2010, at 14:12, Per Vognsen wrote:

Even if the functions can be written in terms of the core protocol,
putting them in the protocol makes it possible to implement
higher-performance specialized versions for some containers while
supplying default implementations in terms of the core protocol
functions via mixins. This is how Scala's Seq trait is designed:

Even though I don't like "me too" posts, I'll make an exception here because I think this is a very important point. I have an example in Clojure in my multiarray library:

        
http://code.google.com/p/clj-multiarray/source/browse/src/multiarray/protocol.clj

The function "rank" in MultiArrayProtocol is redundant in that it can always be implemented as

        (defn rank [x] (count (shape x)))

However, for some implementations, "rank" could just return an integer field from a data structure, instead of constructing a vector for no other purpose than count the number of elements in it. That's why "rank" is a protocol function.

Konrad.

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

To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or 
reply to this email with the words "REMOVE ME" as the subject.

Reply via email to