This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Evaluating Scheme from Java
- From: Mario Domenech Goulart <mario dot goulart at gmail dot com>
- To: kawa at sourceware dot org
- Date: Thu, 17 Jun 2010 06:57:20 -0400
- Subject: Evaluating Scheme from Java
Hi
I'm trying to evaluate Scheme code from Java. The Java code
reads and evaluates the Scheme code which is in a file and calls
Java methods. I'm getting the following error:
$ java -classpath .:api:kawa.jar SchemeLoader test.scm
Exception in thread "main" java.lang.Error: unknown code:f104
at gnu.lists.TreeList.nextDataIndex(TreeList.java:2241)
at gnu.mapping.Values.make(Values.java:82)
at gnu.mapping.CallContext.getFromContext(CallContext.java:282)
at gnu.expr.Language.eval(Language.java:821)
at SchemeLoader.main(SchemeLoader.java:14)
Here's the layout of my code:
SchemeLoader
|-- Makefile
|-- SchemeLoader.java
|-- api
| `-- Foo.java
|-- kawa.jar
`-- test.scm
The contents of the files are:
-------------[ SchemeLoader.java ]-------------
import java.io.*;
import kawa.standard.*;
import gnu.mapping.*;
class SchemeLoader {
public static void main(String[] args) throws Throwable {
Scheme.registerEnvironment();
String filename = args[0];
InPort freader = InPort.openFile(filename);
Scheme scm = new Scheme();
Object x = scm.eval(freader);
System.out.println(x);
}
}
----------[ end of SchemeLoader.java ]----------
---------------[ api/Foo.java ]-----------------
package api;
public class Foo {
public static float add (float a, float b) {
return (a + b);
}
}
------------[ end of api/Foo.java ]--------------
-----------------[ test.scm ]-------------------
(api.Foo:add 4 4)
--------------[ end of test.scm ]---------------
-----------------[ Makefile ]--------------------
all:
javac -classpath .:kawa.jar SchemeLoader.java
javac -classpath .:api:kawa.jar api/Foo.java
clean:
rm -f *~ *.class api/*~ api/*.class
run:
java -classpath .:api:kawa.jar SchemeLoader test.scm
--------------[ end of Makefile ]-----------------
If I replace
(api.Foo:add 4 4)
by
(java.lang.Math:sqrt 9.0)
in test.scm, it works.
I get the error when running "make run" (after building the
source with "make").
Kawa version is 1.9.90 and Java is 1.6.0_20.
I'm afraid I'm terribly missing something. I've placed a tarball
with the code above (and kawa.jar) at
http://parenteses.org/mario/misc/SchemeLoader.tar.gz
Any help is appreciated.
Best wishes.
Mario
--
http://parenteses.org/mario