On Sun, Feb 15, 2009 at 12:31 PM, Mark Volkmann
<r.mark.volkm...@gmail.com> wrote:
>> The :gen-class is only needed if you want to generate a Java class of
>> a certain stripe. It's not required for AOT compilation in general.
>
> What do you mean by "a certain stripe"? I thought :gen-class was
> needed to save the generated bytecode in a .class file.

I was intentionally vague because there are a bunch of different
things gen-class lets you specify.

Here's my understanding:

Main class clojure.lang.Compile will create class files in
*compile-path* (defaulted to System property "clojure.compile.path")
for whatever clojure namespaces you give as args (and namespaces they
depend on, if those namespaces aren't already compiled). Those classes
are all you need to run your app, if for whatever reason you don't
want to distribute your clj files. The Java classes created will have
funny names and (in places) inconvenient APIs, but that's ok because
they for running as Clojure, not for calling from Java.

That's where gen-class comes in: gen-class (or the :gen-class
"reference" in the (ns ...) macro) is for those cases where you want
to let Java code interact with your Clojure code as if it were Java.
It'll create a class with whatever name you want, implement whatever
interface(s) you want, extend whatever superclass you want, etc. (The
less popular gen-interface similarly lets you create a new Java
interface.)

A gen-class'd Java class is pretty weird as Java classes go, since it
looks for the implementations of all its methods in functions of a
Clojure namespace, but from the caller side in Java, you won't know
the difference.

That's all open to correction/clarification from anyone who's used
gen-class more than I, but it seems accurate from what I've seen so
far.

-hume.

-- 
http://elhumidor.blogspot.com/

--~--~---------~--~----~------------~-------~--~----~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to