The following code shows surprising behavior related to using protocol
functions in higher order functions. I sort of understand the reason
wrapped-x first fails is that calling extend-protocol in a sense
redefines the x protocol function. I can't decide if I think this is a
bug or just the way protocols work. I am curious what others think.
-David
====
(defprotocol Foo
(x [this arg]))
(defn wrap [f]
(fn [& args]
(apply f args)))
(def wrapped-x (wrap x))
(extend-protocol Foo
String
(x [this arg]
(str this arg)))
(wrapped-x "hello" "joe")
;; -> No implementation of method: :x of protocol: #'user/Foo found
for class: java.lang.String
(def wrapped-x (wrap x))
(wrapped-x "hello" "joe")
;; -> "hellojoe"
--
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