Re: NPE in reify.
On Tue, Dec 29, 2009 at 01:58:45PM -0500, Rich Hickey wrote: >(type (Small)) >:user/Small > >You can use this keyword type tag for multimethod dispatch. I did eventually figure this out. >I am a bit confused as to why you would want to reify a deftype. You >can reify protocols, however. I need to make something that defines it's own Comparable, and I also want a custom printer for it. Once I figured out that the multimethod dispatch in the printer uses type, and I can just use that on the deftype name, it got much easier. Hopefully there isn't too painful a transition period moving from multimethods to protocols. Thanks, David -- 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: NPE in reify.
On Thu, Dec 24, 2009 at 2:51 AM, David Brown wrote: > The following generates an NPE during compilation: > > (deftype Small []) > (defn wrap [] > (reify Small)) > > Obviously, my real use has more interfaces I implement, but this shows > the problem. > > My problem is that I need to override 'print-method', which is using > defmulti off of 'type' of it's argument. I guess I could also > implement IMeta and provide a tag as well. But, the workaround I've > been using is to create an empty interface in Java, which reify is > happy to implement. > The name Small doesn't designate a class name. It is in fact a factory fn: (deftype Small []) (fn? Small) true (Small) #:Small{} So you can't reify Small any more than you could reify first or rest. The error/message certainly could be better. If you were using AOT, you would have a class named your.ns.Small. But when used dynamically, that class will be something like your.ns.Small__42. However, deftypes are designed to be used dynamically and participate in the 'type' system. The 'type' of a (dynamically or AOT-defined) Small instance will be a keyword: (type (Small)) :user/Small You can use this keyword type tag for multimethod dispatch. I am a bit confused as to why you would want to reify a deftype. You can reify protocols, however. Rich -- 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
NPE in reify.
The following generates an NPE during compilation: (deftype Small []) (defn wrap [] (reify Small)) Obviously, my real use has more interfaces I implement, but this shows the problem. My problem is that I need to override 'print-method', which is using defmulti off of 'type' of it's argument. I guess I could also implement IMeta and provide a tag as well. But, the workaround I've been using is to create an empty interface in Java, which reify is happy to implement. David -- 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