Thu 28 Jul 2016 08:08:32 PM UTC, original submission:
Consider the following example:
import kawa.standard.Scheme;
public class Test {
public static void main(final String[] args) throws Throwable {
final Scheme scheme = new Scheme();
scheme.eval("(define a 1)");
System.out.println(scheme.eval("a"));
}
}
This fails with the following exception:
Exception in thread "main" java.lang.NoSuchFieldError: a
at \^string\_.run(<string>:1)
at gnu.expr.ModuleExp.evalModule2(ModuleExp.java:293)
at gnu.expr.ModuleExp.evalModule(ModuleExp.java:212)
at gnu.expr.Language.eval(Language.java:1298)
at gnu.expr.Language.eval(Language.java:1237)
at gnu.expr.Language.eval(Language.java:1219)
at Test.main(Test.java:7)
The problem seems to be that eval first compiles the given String to a class,
which is then executed, but the class name is always "\^string\_".
(Probably derived from the constant "<string>" identifier?)
There are two workarounds that seem to work:
1) Use Scheme#eval(String, Environment), which seems to do things a little different.
2) Use Scheme#eval(InPort) with a unique Path:
import gnu.kawa.io.InPort;
import gnu.kawa.io.Path;
import kawa.standard.Scheme;
import java.io.StringReader;
public class Test {
public static void main(final String[] args) throws Throwable {
final Scheme scheme = new Scheme();
scheme.eval(
new InPort(new StringReader("(define a 1)"), Path.valueOf("1"))
);
System.out.println(scheme.eval(
new InPort(new StringReader("a"), Path.valueOf("2"))
));
}
}
Currently, I am considering the second workaround, with the String's SHA-1 as Path.
|