Since I moved to Kawa, I’ve been having an issue with maintaining the state between calls to the interpreter. Everything works fine when I load and run an entire file at once (for example when loading the options files or actually debugging my own code), but when I try to run individual lines of code to add custom bindings, it doesn’t work.
So when I run this:
Scheme kawa = new Scheme(); kawa.eval("(define add1 (lambda (n) (+ n 1)))");
It should work, but when I try to use the new code:
Object result = kawa.eval("(add1 5)");
I get a NoSuchFieldError. I could use either
kawa.eval("load \"...\")"), but neither of those is optimal. After hacking around on it for longer than I can to admit, I finally just asked on the Kawa mailing list. Here is my original question, and here is the original response from Jamison Hope (ergo the pun) and another from Per Bothner.
It turns out that I’d actually stumbled upon a bug in Kawa itself that the one argument version of
eval (without an Environment specified) was generating Java code with duplicate class names which eventually ended up causing my error. Per checked in some fixes impressively quickly to work around it and even before then I ended up switching to the two argument version of
eval so that I could otherwise manipulate the Environment object. Problem solved.
The new build is r118, available here.