Moreover, if you're going to extend a particular protocol to many types, it's better to use 'extend-protocol' which expands to a bunch of 'extend-type' forms...if you need a point of reference I recently finished extending a 'DataSet' protocol to all clojure/java data-structures. YOu can find it here : https://github.com/jimpil/hotel-nlp/blob/master/src/hotel_nlp/tools/normalito/core.clj

500 lines of pure protocol extension points! It is that long because a requirement of mine was not to output the same type as the input.

Jim


On 02/08/13 11:55, Jim - FooBar(); wrote:
your extension point on Number is never fired because 10 is a Long. Generally speaking extending protocols to interfaces is not suggested...I've been bitten a couple of times in particular whenever I'm extending to 2 different interfaces that *are* related...You can certainly do it but you have to have sure that your top interface comes first than the others.

Your example is actually fine...try "(hello (int 10))" - you should see "hello"

Jim


On 02/08/13 11:44, Phillip Lord wrote:
I want to use extend-type to support a protocol both on a class and it's
subclasses. But I don't know how to do a superclass call. So for
instance, with this code....

(defprotocol PThree
   (hello [this]))

(extend-type
     Number PThree
     (hello [this]
       (if (= 10 this)
         "hello")))

(extend-type
     Long PThree
     (hello [this]
       (if (= 5 this)
         "goodbye")))

;; this return "goodbye"
(hello 5)
;; this returns nil
(hello 10)


I really want (hello 10) to return "hello". But the extend-type of Long
takes precedence. How can I call the implementation on the superclass
instead?

Phil



--
--
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
--- You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to