Hi,

since IFn is a Java interface and not a protocol, I'm afraid there is no 
better way to define this. However I would write the macro slightly 
differently. I find this more approachable. YMMV.

(def max-arities 20)

(defmacro definvokable
  [type fields & deftype-tail]
  (let [f        (fields 0)
        args     (repeatedly max-arities gensym)
        arity    (fn [n]
                   (let [args (take n args)]
                     `(invoke [this# ~@args] ((. this# ~f) ~@args))))
        vararg   `(invoke [this# ~@args more#]
                    (apply (. this# ~f) ~@args more#))
        apply-to `(applyTo [this# args#] (apply (. this# ~f) args#))]
    `(deftype ~type
       ~fields
       clojure.lang.IFn
       ~@(map arity (range (inc max-arities)))
       ~vararg
       ~apply-to
       ~@deftype-tail)))

Sincerely
Meikel

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to