On Fri, Nov 21, 2008 at 05:46:00AM -0800, Rich Hickey wrote:
> I'd appreciate examples of gen-and-load-class and gen-and-save-class
> use not well supported by the AOT gen-class.
> 
> What I am interested in is the scenarios/use-cases.


I've got a DSL which compiles an abstraction to a class. These abstractions
are accessible from the rest of the Java platform, and fit very nicely as
classes (with immutable fields and pure methods). The DSL accesses metadata
on previously defined abstractions to generate new ones, and some of the
base abstractions are written directly in Java for performance. Basically,
classes provide a common meeting ground across the JVM.


Now, I can see a standard way of doing something like this

(defmacro def-gen-class [name & options]
  (let [{:keys [name bytecode]}
        (eval `(gen-class ~(str name) [EMAIL PROTECTED]))]
    (if *compile-files*
      (.writeClassFile Compiler (.replace name "." "/")
                                bytecode)
      (.. clojure.lang.RT ROOT_CLASSLOADER
          (defineClass (str name) bytecode)))

  '(do)))

(Haven't thought much about the proper phasing. But I used a macro so that
nothing is left around after compile-time)


Do you have something against Java classes, or does Clojure only shun them
because they can't be redefined? Being a JVM language, I would think a full
(defclass ..) form would be a no-brainer, for exporting APIs to rest of Java
land.


Steve


--~--~---------~--~----~------------~-------~--~----~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to