On Wed, Jul 22, 2009 at 8:16 AM, Stuart Sierra<the.stuart.sie...@gmail.com> wrote: > > On Jul 21, 6:55 pm, Howard Lewis Ship <hls...@gmail.com> wrote: >> It would be nice if (gen-class), when not in compile mode, would still >> create a class in memory that could be referenced by class name >> elsewhere in Clojure. > > The gen-class function does nothing unless the *compile-files* var is > true. So you should be able to do: > > (binding [*compile-files* true] > (gen-class ...)) > > To generate classes at run-time. As others have mentioned, though, > you can't redefine a named class in Java once it's been loaded. >
Actually, no. You can't redefine a named class *in the same classloader*. However if you create a new class loader to contain the new class, you can make it work. Tapestry has been doing this for a few years now (it actually reads the bytecode for a base class then does an AOP-style transformation on the code before loading the transformed class into a new class loader). This would be both harder and easier to do in Clojure. Because of Vars, its pretty easy to get rid of references to the old function, class and class loader. However, because of functional closures, you will often be holding a reference to a function (and it's class, and it's class loader). Still, this may be acceptable if you consider running Clojure code without AOT to be "development mode" and running Clojure code with AOT to be "production mode". -- Howard M. Lewis Ship Creator of Apache Tapestry Director of Open Source Technology at Formos --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---