let me explain with an example:

;;in some namespace x

(defprotocol IStemmable
(stem [this token] [this token lang])
(getRoot [this token dictionary]))

(defprotocol IDistance
(getDistance [this s1 s2] [this s1 s2 m-weight]))

;;in some namespace y that refers all vars from x

(extend-type String
 IStemmable
 (stem
  ([this] (stem this "english"))
  ([this lang]
     (let [stemmer (help/porter-stemmer lang)]
        (doto stemmer
                (.setCurrent this)
                (.stem))
          (.getCurrent stemmer))))
 (getRoot [this _ dic] (get dic this "NOT-FOUND!"))
 IDistance
 (getDistance
   ([this other]
      (help/levenshtein-distance* this other)) ;;delegate to helper fn
   ([this other mismatch-weight]
(help/levenshtein-distance* this other mismatch-weight)))) ;;same here


(defrecord PorterStemmer [lang input output] ;;COMPILES AND WORKS FINE - NO PROBLEMS
IStemmable
(stem [_ token]
  (stem token lang))       ;;delegate to String for this
(getRoot [_ token dic]
  (getRoot token _ dic)))) ;;delegate to String for this


(defrecord LevenshteinDistance []  ;;DOESN'T COMPILE
IDistance
(getDistance [_ s1 s2]
  (getDistance s1 s2))  ;;delegate to String for this
(getDistance [_ s1 s2 weight]
  (getDistance s1 s2 weight)))  ;;and this


trying to load the file results in:

CompilerException java.lang.IllegalArgumentException: No single method: getDistance of interface: cluja.protocols.IDistance found for function: getDistance of protocol: IDistance, compiling:(/media/sorted/uni_stick/cluja/src/cluja/concretions/models.clj:152:3)

What am I doing wrong? I am practically doing the exact same thing for these 2 protocols. Both of them delegate to the implementations extended to string. I keep looking at the code and I see nothing wrong! The 'getDistance' with 3 args delegates to the one with 2 and the one with 4 delegates to the one with 3 (from String)...even more confusingly why one works and the other complains? any ideas/insights?

Jim

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