The only thing different is that it will require any methods or
functions you have in your class namespace start with an underscore if
you want them to hook up to method names or other names given in your
gen-and-*-class call.
Here's the smallest example I could come up with:
(gen-and-load-class 'chouser.MiniTest :init 'myinit)
(in-ns 'chouser.MiniTest)
(clojure/refer 'clojure)
(defn myinit [] (prn "hi"))
That's the old way. To fix that to work with this patch, replace myinit with:
(defn _myinit [] (prn "hi"))
The benefit of this is that your chances of a name conflict on the
(clojure/refer 'clojure) call (or any other refer) goes from "very
likely" to "almost zero".
This name mangling was discussed on IRC:
http://clojure-log.n01se.net/date/2008-07-25.html#15:31c-16:17a
It's entirely Rich's idea, but of course I don't speak for Rich and
can't say if this implementation or even this type of solution will be
incorporated into Clojure proper.
I barely know what's going on in gen-class, but the attached example
seems to work. What do you all think?
--Chouser
Before either of these patches:
(gen-and-load-class 'net.n01se.MiniTest :init 'myinit)
(in-ns 'net.n01se.MiniTest)
(clojure/refer 'clojure)
(defn myinit [] (prn "hi"))
With this latest patch:
(gen-and-load-class 'net.n01se.MiniTest :init 'myinit)
(clojure/in-ns 'net.n01se)
(clojure/refer 'clojure)
(defn MiniTest-myinit [] (prn "hi"))
Note that for the same class name, the namespace is different -- it
now indicates just the package name (net.n01se instead of
net.n01se.MiniTest). The classname is now included
with each function name (MiniTest-myinit instead of myinit).
--Chouser
Sorry, I forgot to update the doc string. Also the examples in the
(comment) at the end are now completely out of date. This subsequent
patch fixes both.
--Chouser