This is the mail archive of the
mailing list for the Kawa project.
Re: Using Kawa as an embedded scripting language
On Aug 25, 2011, at 1:45 PM, John-Paul Verkamp wrote:
I'm writing a project uses Kawa as an embedded scripting language, but
one part of the behavior is a little puzzling.
I'm doing this:
Scheme kawa = new Scheme();
kawa.eval("(define add1 (lambda (n) (+ n 1)))");
But when I try to use the add1:
Object result = kawa.eval("(add1 5)");
I'm getting a NoSuchFieldError from the ModuleExp class.
Alternatively, if I use kawa.defineFunction(...) to define add1 or put
in in a file and use kawa.eval("(load \"add1.ss\")") it works just
I managed to work around the issue for the time being by automatically
wrapping any top-level S-expressions that I pass to kawa.eval with
Scheme's eval; for example:
kawa.eval("(eval '(define add1 (lambda (n) (+ n 1))))")
But that feels hacky (and doesn't work with some more complicated
Is there something I'm doing wrong / should be doing to make this
Thanks ahead of time for any assistance.
I'm not sure why that doesn't work, but I'm guessing that the one-
eval isn't using the right Environment. Try this instead:
Scheme kawa = Scheme.getInstance(); // or new Scheme();
Environment env = Environment.getCurrent();
kawa.eval("(define add1 (lambda (n) (+ n 1)))", env);
Object result = kawa.eval("(add1 5)", env);
That works for me.
The PTR Group