Modified gen-class to fit more into common conventions

0 views
Skip to first unread message

Meikel Brandmeyer

unread,
Nov 4, 2008, 1:36:29 PM11/4/08
to clo...@googlegroups.com
Hi,

I attached a patch, which addresses some issues I have with gen-class.

- gen-class does load a specifically named file instead of
requiring a namespace. This leads to an artificial splitting
of the sources. Furthermore setup of support has to be
repeated over and over again. (Once per class in that namespace)

- gen-class handles _ differently than the library functions.
So the namespace for foo_bar.Baz must be called foo_bar instead
of foo-bar.

The patch addresses these issues. So a usage of gen-class, with
applied patch might look like this:

In in/the/classpath/foo_bar/foo_bar.clj:
(clojure/ns foo-bar)

(defn Baz-toString
[this]
"A Baz!")

The gen-class call unchanged:
(gen-and-save-class "in/the/classpath" 'foo_bar.Baz)

Usage:
user=> (def b (new foo_bar.Baz))
#=(var user/b)
user=> (.toString b)
"A Baz!"

My knowledge about generating JVM bytecode is limited to guessing
the correct looking enchantments. Although not really tested, it seems
to work.

I think this would make gen-class look a lot less kludgy, since now it
adheres to the usual conventions: - for lisp code, _ for Java code and
the namespace as responsible for setting up things.

The downside: this would be an incompatible change.

Any thoughs or comments?

Sincerely
Meikel

gen-class.patch
Reply all
Reply to author
Forward
0 new messages