taoensso / timbre

Pure Clojure/Script logging library
https://www.taoensso.com/timbre
Eclipse Public License 1.0
1.44k stars 171 forks source link

Defnp with arity overloaded functions #72

Closed ribcakes closed 10 years ago

ribcakes commented 10 years ago

When trying to wrap a multiple arity function with defnp, an error is returned, e.g:

(defnp hi 
  ([] "hi") 
  ([name] (str "hi" name)))
IllegalArgumentException 
Invalid signature {} should be a list 
clojure.core/assert-valid-fdecl/fn--6503 (core.clj:6726)

user=> (pst)
nil
IllegalArgumentException Invalid signature {} should be a list
    clojure.core/assert-valid-fdecl/fn--6503 (core.clj:6726)
    clojure.core/map/fn--4215 (core.clj:2487)
    clojure.lang.LazySeq.sval (LazySeq.java:42)
    clojure.lang.LazySeq.seq (LazySeq.java:60)
    clojure.lang.RT.seq (RT.java:484)
    clojure.core/seq (core.clj:133)
    clojure.core/filter/fn--4234 (core.clj:2523)
    clojure.lang.LazySeq.sval (LazySeq.java:42)
    clojure.lang.LazySeq.seq (LazySeq.java:67)
    clojure.lang.RT.seq (RT.java:484)
    clojure.core/seq (core.clj:133)
    clojure.core/assert-valid-fdecl (core.clj:6730)

More information:

user=> (macroexpand-1 '(defnp hi
                         ([] "hi")
                         ([name] (str "hi" name))))
(clojure.core/defn hi 
  ([] "hi") {} 
  (taoensso.timbre.profiling/pspy "hi" ([name] (str "hi" name))))
ptaoussanis commented 10 years ago

Hey Brian! defnp doesn't support the multi-arity case because:

(defnp hi 
  ([] (p :nullary-case "hi"))
  ([name] (p: unary-case (str "hi" name))))

This should be documented though; thought it was. Will update shortly so thanks for the report!

Hope that helps? Cheers :-)