This is the mail archive of the
kawa@sources.redhat.com
mailing list for the Kawa project.
creating classes at runtime
- From: Robert Nikander <rob at encodia dot biz>
- To: kawa at sources dot redhat dot com
- Date: Mon, 25 Apr 2005 10:44:46 -0700
- Subject: creating classes at runtime
I'm looking for a way to create instances from classes defined in .scm
files that are written at runtime.
Is there a recommended way to do this? I'm guessing that (load file)
is the way, but it's behavior is surprising me.
I'm calling (load "foo.scm") and I thought that any define-simple-class
in foo.scm would be available via Class.forName. But
Class.forName("FooClass") throws ClassNotFoundException. I can,
however, create a FooClass with (make <FooClass>). I also notice that
if I rewrite and reload foo.scm, the (make <FooClass>) will create an
instance of the new class. How does this work? I thought Java
couldn't redefine a class once it was loaded?
Right now, I'm thinking I can instantiate the dynamically created class
like this:
(write-scm-file file-name)
(load file-name)
(eval `(make ,class-name))
Is there a better way?
Rob