define-simple-class vs modules
Per Bothner
per@bothner.com
Tue Jan 25 23:49:00 GMT 2011
On 01/25/2011 02:25 PM, Jamison Hope wrote:
> Once upon a time (before 1.10, probably), I was able to do something
> like this:
>
> $ cat Test.scm
> (define-simple-class Test ()
> ((*init*) (display "Created an instance") (newline)))
>
> but now when I try to compile it:
>
> $ java kawa.repl -C Test.scm
> (compiling Test.scm to Test)
> Test.scm:2: internal error while compiling Test.scm
> java.lang.Error: calling <init> on already-initialized object
> at gnu.bytecode.CodeAttr.emitInvokeMethod(CodeAttr.java:1498)
> It seems I can no longer define-simple-class a Java class with the name
> of the Scheme file. That name gets reserved for a mandatory "module"
> class, even if the simple-class is the only definition in the whole
> file. Was it just an accident that it worked before?
Basically. It might work in some cases, but could easily break.
In fact, relatively recently I made changes just so this *should* work
more generally. And it does, if you leave out the *init*.
Haven't yet figured out why the *init* is causing problems,
but am looking into it.
> Relatedly, if I wanted to use module-extends and module-implements
> instead of define-simple-class: How would I define constructors?
It's not supported. I'm not convinced it's a good idea.
> Can I use (this) in the body of a function?
Not sure ... It may be best to not allow it, to avoid questionable
usages and unintentional mistakes.
>Are annotations supported?
To some extent - at least for functions, I believe.
--
--Per Bothner
per@bothner.com http://per.bothner.com/
More information about the Kawa
mailing list