Re: Can (genclass) be changed to operate when not compiling?
I see in clojure.core that you have gen-and-load-class . This may be what you are after ? HTH, -- Laurent 2009/7/22 Howard Lewis Ship hls...@gmail.com I'm using (:gen-class) to create javax.servlet.Filter, then creating a Jetty instance around the filter. Alas, for this to work, I have to go through my compile build to create the filter class so that I can let Jetty instantiate the filter. 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. My goal here is to use the exact same Filter class whether running embedded (i.e., starting up Jetty from Clojure) or deployed (a traditional WAR with the same filter configured in web.xml). -- 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 -~--~~~~--~~--~--~---
Re: Can (genclass) be changed to operate when not compiling?
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. -SS --~--~-~--~~~---~--~~ 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: Can (genclass) be changed to operate when not compiling?
On Wed, Jul 22, 2009 at 8:16 AM, Stuart Sierrathe.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 -~--~~~~--~~--~--~---
Re: Can (genclass) be changed to operate when not compiling?
Howard, Is there a chance that you consider making Cascade servlet- independent? It would be great if Cascade application could be also run, for example, directly as a grizzlet (or some other yet-to-be- created technology). Is there an absolute need to depend on servlets now when we have Clojure's advanced concurrent models and immutability? On Jul 22, 5:46 pm, Howard Lewis Ship hls...@gmail.com wrote: On Wed, Jul 22, 2009 at 8:16 AM, Stuart Sierrathe.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 -~--~~~~--~~--~--~---
Can (genclass) be changed to operate when not compiling?
I'm using (:gen-class) to create javax.servlet.Filter, then creating a Jetty instance around the filter. Alas, for this to work, I have to go through my compile build to create the filter class so that I can let Jetty instantiate the filter. 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. My goal here is to use the exact same Filter class whether running embedded (i.e., starting up Jetty from Clojure) or deployed (a traditional WAR with the same filter configured in web.xml). -- 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 -~--~~~~--~~--~--~---
Re: Can (genclass) be changed to operate when not compiling?
Howard Lewis Ship hls...@gmail.com writes: 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. +1 I would find this useful as well. Cheers, Chris Dean --~--~-~--~~~---~--~~ 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: Can (genclass) be changed to operate when not compiling?
On Tue, Jul 21, 2009 at 8:04 PM, Howard Lewis Shiphls...@gmail.com wrote: Basically, what I want is for AOT to be an optional optimization, not a requirement. Currently if your code relies on gen-class, AOT becomes necessary for operation, period. This is how gen-class used to behave. Unfortunately, it causes problems because named classes can't be changed once they're loaded in the JVM. I think there are also classloader issues that I don't yet fully understand. Named classes and named interfaces must be created before the JVM is started. --Chouser --~--~-~--~~~---~--~~ 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: Can (genclass) be changed to operate when not compiling?
I get around this for servlets by combining gen-class and proxy in my servlet file; (ns my-servlets.MyServlet (:import (javax.servlet.http HttpServlet HttpServletRequest HttpServletResponse)) (:gen-class :extends HttpServlet) ) (defn req-do [#^HttpServlet svlt #^HttpServletRequest req #^HttpServletResponse rsp] (do-stuff)) (defn -service [#^HttpServlet svlt #^HttpServletRequest req #^HttpServletResponse rsp] (req-do svlt req rsp) ) (def my-servlet (proxy [HttpServlet] [] (service [req rsp] (req-do this req rsp Then for production (tomcat), an ant build compiles and deploys the war with web.xml referring to myservlets.MyServlet and in my dev environment, I launch a jetty instance with my-servlet in a jetty servlet holder. I haven't done this with Filters yet, but I'm pretty sure you could use a similar approach? Hth, Adrian. On Wed, Jul 22, 2009 at 4:40 AM, Chouserchou...@gmail.com wrote: On Tue, Jul 21, 2009 at 8:04 PM, Howard Lewis Shiphls...@gmail.com wrote: Basically, what I want is for AOT to be an optional optimization, not a requirement. Currently if your code relies on gen-class, AOT becomes necessary for operation, period. This is how gen-class used to behave. Unfortunately, it causes problems because named classes can't be changed once they're loaded in the JVM. I think there are also classloader issues that I don't yet fully understand. Named classes and named interfaces must be created before the JVM is started. --Chouser --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---