This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Interaktion between Scheme and Java


Marco Bakera wrote:
However, even that doesn't work. I tried it this way as one could see
in the attachment of the last mail i wrote about.

So here are the essential steps i don't find the failure at:

scheme/TestScheme.scm:
======================
(define (theFirst list)
  (car list))

Then invoking:
==============
kawa -d scheme/bin -P de.bakera.kawa. -C scheme/SchemeTest.scm

Test.java:
==========
List l = new ArrayList();
l.add("one");
l.add("two");
		
LList llist = LList.makeList(l);
System.out.println("Test.main() llist=" + llist);
	
System.out.println("Test.main() fst = "
		+ SchemeTest.theFirst(llist));

output:
=======
Test.main() llist=(one two)
Exception in thread "main" java.lang.ExceptionInInitializerError
	at de.bakera.kawa.SchemeTest.theFirst(SchemeTest.scm:2)
	at Test.main(Test.java:36)
Caused by: java.lang.NullPointerException
	at gnu.mapping.InheritingEnvironment.lookupInherited(InheritingEnvironment.java:72)
	at gnu.mapping.InheritingEnvironment.getLocation(InheritingEnvironment.java:100)
	at gnu.mapping.Environment.getLocation(Environment.java:117)
	at gnu.expr.ModuleInfo.find(ModuleInfo.java:100)
	at gnu.expr.ModuleInfo.register(ModuleInfo.java:115)
	at kawa.lib.lists.<init>(lists.scm)
	at kawa.lib.lists.<clinit>(lists.scm)
	... 2 more


I don't know how to interpret the output. Does anyone perhaps has any suggestions about this problem? Or just a simple step-by-step tutorial to teach kawa figuring out about symbols?

You're clearly using Java-5, since the SchemeTest.sq(3) in Test.java depends on autoboxing.

When I changed SchemTest.scm to use an <int paramater thus:
(define (sq (x :: <int>))
  (* x x))
it (surprisingly?) worked:
Test.main() sq 3 = 9
Test.main() llist=(one two)
Test.main() fst = one

Alternatively, we can leave SchemeTest.scm alone, and manually
box to a Scheme integer:
System.out.println("Test.main() sq 3 = " + SchemeTest.sq(gnu.math.IntNum.make(3)));
This also works.

Or we can manually box to java.lang.Integer:
System.out.println("Test.main() sq 3 = " + SchemeTest.sq(new java.lang.Integer(3)));
This also works, but the support for mixing Scheme numbers with java.lang.Integer
is relatively new and incomplete, so may not always work.

Finally, what may be the reason for the failure you're seeing.
Just calling a Scheme procedure as Java method is not always guaranteed
to work.  Sometimes the method will be a non-static rather than a static
method.  Other times, the compiler will assume that initialization has
been done.  So it's only *accidental* that it works for me - and doesn't
work for you.

What you might want to do is to compile your Scheme modules with
--module-static or --module-static-run.  The latter (which appears
not to be document in the manual ...) also causes the "body" (top-level
expressions) of the module to be invoked by the static constructor.
--
	--Per Bothner
per@bothner.com   http://per.bothner.com/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]