Hi Stuart. thank you for pointing me to my 'cloSure' misspelling. Have lived in the Scheme world for too long :-)
As to Java classes generation, IMHO it is more save to generate Java bytecode directly instead of using intermediate Java sources. This is how I create classes now using a generator written in Java. Now I have to re-write this generator in CloJure. Regards, Vladimir On Monday, November 5, 2012 1:09:11 AM UTC+4, Stuart Sierra wrote: > > Hello, > > Clojure (by the way, it is not spelled "closure") is not really designed > to generate pure-Java classes. `gen-class` is slightly more flexible than > `deftype`, but it will still generate references to Clojure classes. > > If the structure of your Java classes is defined by interfaces, `deftype` > can implement those interfaces. But if the structure of the Java classes is > very regular, you may find it easier to generate Java source code as > strings. That's how all the primitive interfaces in clojure.lang.IFn were > created. > > -S > > > > On Sunday, November 4, 2012 4:43:59 AM UTC-5, Vladimir Tsichevski wrote: >> >> Thank you Stephen, >> >> the problem is that it is impossible to create create a Java class using >> closure with the following characteristics: >> >> 1) all methods must match given Java signature. For example, if I need a >> method >> >> public String getSomeString(); >> >> all I get is >> >> public Object getSomeString(); >> >> closure ignores my String hints and always uses Object instead. >> >> 2) must be no references to any closure classes. Now the closure compiler >> unconditionally creates at least one extra method >> >> public static IPersistentVector getBasis() >> >> which references several classes from closure runtime. >> >> Regards, >> Vladimir >> >> On Sat, 2012-11-03 at 13:57 -0700, Vladimir Tsichevski wrote: >>> > In one of my purely Java project I have to create hundreds of java >>> classes >>> > with repeatable structure, so the task is an excellent candidate for >>> > automation. I hoped I will be able to create these classes with the >>> latest >>> > closure, using the 'deftype' construct. >>> >>> If you know all the details of classes to create at compile time, you >>> can use macros instead, which are perfectly well able to output deftype >>> forms. Untested: >>> >>> (defmacro defrefs >>> "Make a bunch of :x boxes." >>> [& names] >>> `(do ~@(map (fn [name] `(defrecord ~name [~'x])) names))) >>> >>> ;; makes classes foo, bar, baz, qux, quux, all with the :x field. >>> (defrefs foo bar baz qux quux) >>> >>> -- >>> Stephen Compall >>> ^aCollection allSatisfy: [:each|aCondition]: less is better >>> >>> >>> -- 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