On Sat, Jun 18, 2011 at 4:44 AM, Sam Aaron <samaa...@gmail.com> wrote:
> Is it possible to use this approach to create a callable record which can 
> take a variable number of arguments?
>
> I can't get the following to work:
>
> (defrecord Foo [a]
>  clojure.lang.IFn
>  (invoke [this & args] (println (str a args))))
>
> (def yo (Foo. "sam"))
>
> (yo 1 2 3 4) ;=> 
> sc-one.Foo.invoke(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
>    [Thrown class java.lang.AbstractMethodError]

Not easily. You may be able to override applyTo to get that to work.
Alternatively, you can work around it by using destructuring and an
extra vector around the args:

(defrecord Foo [a]
  clojure.lang.IFn
  (invoke [this [& args]] (println (str a args))))

(def yo (Foo. "sam"))

(yo [1 2 3 4])

A bit ugly, but it should work.

-- 
Protege: What is this seething mass of parentheses?!
Master: Your father's Lisp REPL. This is the language of a true
hacker. Not as clumsy or random as C++; a language for a more
civilized age.

-- 
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