Note that there are some explanatory texts on larger screens.

plurals
  1. POIssue with protocols in Clojure: "No single method: ..." error
    text
    copied!<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/5401378/do-clojure-protocols-allow-one-to-have-a-variadic-method-the-way-funcions-do-wi">Do clojure protocols allow one to have a variadic method the way funcions do (with an ampersand)?</a> </p> </blockquote> <p>I'm getting this error when running some Clojure code using a protocol:</p> <pre><code>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) </code></pre> <p>Here's the code in question:</p> <pre><code>(defprotocol Entity (add-component [this cname &amp; args]) (update-component [this cname f &amp; args]) (remove-component [this cname]) (get-component [this cname]) (has-component? [this cname])) (extend-protocol Entity clojure.lang.IPersistentMap (add-component [this cname &amp; args] (assoc entity cname (apply new-component cname args))) (update-component [this cname f &amp; 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 &amp; args] (alter this (apply add-component cname args))) (update-component [this cname f &amp; 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))) </code></pre> <p>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?</p> <p>Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload