This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: Calling getClass() on a Scheme subclassed object
- From: Sean Luke <sean at cs dot gmu dot edu>
- To: kawa at sources dot redhat dot com
- Date: Tue, 30 May 2006 00:06:43 -0400
- Subject: Re: Calling getClass() on a Scheme subclassed object
- References: <E728E3CE-22E5-4F5B-A348-70FD9ADAFE2A@cs.gmu.edu>
After some further reading on the list, I've seen (invoke <Foo>
'getReflectClass), which returns
class Foo
That looked lots more promising, until I actually tried using it:
(<sim.engine.SimState>:doLoop (invoke <Foo> 'getReflectClass)
(<java.lang.String[]> (*:toString "-until") (*:toString 5000))
MASON Version 12. For further options, try adding ' -help' at end.
Job: 0 Seed: 1148961645567
Starting Foo
Invalid parameter, was: Foo
java.lang.ClassCastException: Foo
at ca.step(ca.scm:11)
at sim.engine.Repeat.step(Schedule.java:497)
at sim.engine.Schedule.step(Schedule.java:219)
at sim.engine.SimState.doLoop(SimState.java:483)
at sim.engine.SimState.doLoop(SimState.java:294)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at gnu.expr.PrimProcedure.apply(PrimProcedure.java:238)
at gnu.mapping.CallContext.runUntilDone(CallContext.java:251)
at gnu.expr.ModuleExp.evalModule(ModuleExp.java:268)
at kawa.Shell.run(Shell.java:230)
at kawa.Shell.run(Shell.java:172)
at kawa.Shell.run(Shell.java:159)
at kawa.repl.main(repl.java:846)
The doLoop method constructs a Foo using reflection, and ultimately
passes the instance to ca.step (ca is another Scheme simple-class).
In the step method we see:
(define-simple-class <ca> (<sim.engine.Steppable>)
((step (state :: <sim.engine.SimState>)) :: <void>
(let ((tut :: <Foo> (as <Foo> state)) ...
So step is being handed an instance of whatever class was provided in
(invoke <Foo> 'getReflectClass), and it's now trying to cast that
instance into a <Foo>. That *ought* to work but it doesn't.
Sean
On May 29, 2006, at 11:52 PM, Sean Luke wrote:
I maintain a simulation toolkit (MASON) in Java and have been
interested in seeing if I can get some simulation apps written in
Scheme rather than in raw Java. So far I've been successful, and
after heavily typing the scheme code, it runs at very close (about
1.5) the speed of my Java code. Not bad!
Unfortunately I'm stuck with a difficulty. In the system you
typically create a subclass of a Java class (sim.engine.SimState),
and then populate that class with various data to form your
simulation model. Let's say your simulation is called
sim.app.Foo. The most straightforward way to run your simulation
is to then call the following method:
doLoop(sim.app.Foo.class, ...)
In Scheme, I create the subclass using define-simple-class:
(define-simple-class <Foo> (<sim.engine.SimState>) ... )
But I am utterly stymied as to how to pass the "Class" for the
<Foo> scheme class into the doLoop method. For example, this works
using a preexisting Java simulation:
(<sim.engine.SimState>:doLoop
<sim.app.tutorial1and2.Tutorial1>:class (<java.lang.String[]>
(*:toString "-help")))
But doing something like this:
(<sim.engine.SimState>:doLoop <Foo>:class (<java.lang.String[]>
(*:toString "-help")))
... fails because <Foo> isn't a class but is a
gnu.bytecode.ClassType, and the documentation is pretty scarce
about how (or if it's even possible) to extract the class proper
out of this beast. Ideas?
Sean