There are a several small things here that need fixing:
- in the “gran” section of your “extend”, you’re defining “blap” which is not part of the gran protocol
- perhaps blip was intended
- the first argument in protocol function declarations refers to the object itself, often named “this”
- calls to protocol functions don’t begin with “.”
- the call to (:blip this) had the wrong arity
Here is something similar that prints 6:
(assoc w :blip (fn [this x y z] (+ x y z)))))
((:blip this) this x y z))})
(println (blip (new-wackel {}) 1 2 3))
- also consider extend-type in preference to extend here for its somewhat friendlier syntax.
—Steve
This is not working for me:
(ns aatree.record-play)
(defprotocol gran
(blip [x y z]))
(defrecord wackel [])
(defn new-wackel [opts]
(let [w (->wackel)]
(into w opts)
(assoc w :blip (fn [this x y z] (+ x y z)))))
(extend wackel
gran
{:blap (fn [this x y z]
((:blip this) x y z))})
(println (.blap (new-wackel {}) 1 2 3))
I get this: No matching method found: blap for class aatree.record_play.wackel
I changed the println to this:
(let [^gran w (new-wackel {})]
(println (.blap w 1 2 3)))
And now I get this: Unable to resolve classname: gran
Clearly there is something about protocols and/or extend that I do not understand.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to
clo...@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+u...@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+u...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.