I want to have a function in my type that takes an optional argument. I have successfully used optional arguments in functions that are not of type, however I cannot get it to work in protocol and type.
My failed test:
Clojure 1.4.0 user=> (defprotocol OptArg (func [this a & b])) OptArg user=> (deftype Imp [] OptArg (func [this a & b] (println ab))) user.Imp user=> (func (Imp.) 1 2) CompilerException java.lang.IllegalArgumentException: No single method: func of interface: user.OptArg found for function: func of protocol: OptArg, compiling:(NO_SOURCE_PATH:5) user=> (defn opt-arg [a & b] (println ab)) #'user/opt-arg user=> (opt-arg 1 2) 1 (2) nil user=> (opt-arg 1) 1 nil nil user=>
user972946
source share