1

Possible Duplicate:
Do clojure protocols allow one to have a variadic method the way funcions do (with an ampersand)?

I'm getting this error when running some Clojure code using a protocol:

Exception in thread "main" java.lang.IllegalArgumentException: No single method: add_component of interface: questar.entity.Entity found for function: add-component of protocol: Entity, compiling:(questar/entity.clj:17)

Here's the code in question:

(defprotocol Entity
  (add-component [this cname & args])
  (update-component [this cname f & args])
  (remove-component [this cname])
  (get-component [this cname])
  (has-component? [this cname]))

(extend-protocol Entity
  clojure.lang.IPersistentMap
    (add-component [this cname & args]
      (assoc entity cname (apply new-component cname args)))
    (update-component [this cname f & args]
      (let [component (get-component this cname)]
        (add-component this cname (apply f component args))))
    (remove-component [this cname]
      (dissoc this cname))
    (get-component [this cname]
      (this cname))
    (has-component? [this cname]
      (contains? this cname))

  clojure.lang.IDeref
    (add-component [this cname & args]
      (alter this (apply add-component cname args)))
    (update-component [this cname f & args]
      (alter this (apply update-component cname f args)))
    (remove-component [this cname]
      (alter this remove-component cname))
    (get-component [this cname]
      (get-component this @cname))
    (has-component? [this cname]
      (has-component? this @cname)))

I know this can be related to the arity, but everything looks correct to me. Is this because it can't figure out which version of add-component to call?

Thanks!

Community
  • 1
  • 1
Mark A. Nicolosi
  • 82,413
  • 11
  • 44
  • 46
  • I think amalloy is right, and that question has good answers. – Chouser Dec 17 '11 at 16:46
  • amalloy: Yes, it's a dup. Do I need to delete this? Chouser: I saw your answer before you deleted it and I appreciated the work-around you offered. Sadly your work-around is not mentioned on the other question. – Mark A. Nicolosi Dec 17 '11 at 17:48
  • @user1103052 No, the way it works is if enough (five) people vote to close the question within some period of time (two days?), then it's automatically closed, and a big ol' header goes at the top redirecting to the other page (I think). So you shouldn't have to do anything about it, though you can if you want. – amalloy Dec 17 '11 at 23:37

0 Answers0