Re: Records implementing IFn
Thank you. That seems to do the trick. -Mark On Feb 7, 11:55 pm, Alex Osborne wrote: > Mark Fredrickson writes: > > Is the following behavior correct or a bug: > > > user> (defrecord Example [data] clojure.lang.IFn (invoke [this] this) > > (invoke [this n] (repeat n this))) > > user.Example > > user> (def e (Example. "I am e")) > > #'user/e > > user> (e 2) > > (#:user.Example{:data "I am e"} #:user.Example{:data "I am e"}) > > user> (def some-es (e 5)) > > ; Throws java.lang.AbstractMethodError > > > I can't tell if I am doing something wrong with respect to the IFn > > definition, or if I am encountering a bug. > > I think you need to implement applyTo for a properly working IFn > implementation: > > (defrecord Example [data] clojure.lang.IFn > (invoke [this] this) > (invoke [this n] (repeat n this)) > (applyTo [this args] (clojure.lang.AFn/applyToHelper this args))) -- 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
Re: Records implementing IFn
Mark Fredrickson writes: > Is the following behavior correct or a bug: > > user> (defrecord Example [data] clojure.lang.IFn (invoke [this] this) > (invoke [this n] (repeat n this))) > user.Example > user> (def e (Example. "I am e")) > #'user/e > user> (e 2) > (#:user.Example{:data "I am e"} #:user.Example{:data "I am e"}) > user> (def some-es (e 5)) > ; Throws java.lang.AbstractMethodError > > I can't tell if I am doing something wrong with respect to the IFn > definition, or if I am encountering a bug. I think you need to implement applyTo for a properly working IFn implementation: (defrecord Example [data] clojure.lang.IFn (invoke [this] this) (invoke [this n] (repeat n this)) (applyTo [this args] (clojure.lang.AFn/applyToHelper this args))) -- 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
Records implementing IFn
Is the following behavior correct or a bug: user> (defrecord Example [data] clojure.lang.IFn (invoke [this] this) (invoke [this n] (repeat n this))) user.Example user> (def e (Example. "I am e")) #'user/e user> e #:user.Example{:data "I am e"} user> (e 2) (#:user.Example{:data "I am e"} #:user.Example{:data "I am e"}) user> (e) #:user.Example{:data "I am e"} user> (def some-es (e 5)) ; Throws java.lang.AbstractMethodError I can't tell if I am doing something wrong with respect to the IFn definition, or if I am encountering a bug. I have not tried building up a deftype by hand. That may well solve my problem and would be a perfectly acceptable solution. I started with a record to hold immutable data and implement the meta-data protocol, but I could implement these on a type (perhaps dropping another protocol/interface if it is causing the problem above). Thanks in advance, -Mark -- 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