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] Sam --- http://sam.aaron.name On 15 Jun 2011, at 20:57, Ken Wesson wrote: > On Wed, Jun 15, 2011 at 3:53 PM, RJ Nowling <rnowl...@gmail.com> wrote: >> Hi, >> >> I'm sorry if this has been asked before, but I would like to know how >> to create data structures in Clojure that can be used in the same way >> as the built-in data structures. For example, I can access the >> elements of a vector by (my-vec 1). How can I implement this >> interface when creating a data structure in Clojure? > > (defrecord Foo [...] > ... > IFn > (invoke [this] (do-this-on-zero-argument-call)) > (invoke [this x] (do-when-called-with-x)) > (invoke [this x y] (+ x y))) > > => ((Foo.) 33 9) > 42 > => > > -- > 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 -- 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