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: Using Kawa as an embedded scripting language


That worked perfectly, although I did tweak one thing. The two
argument eval is static, so I used

>> Scheme.eval("...", evn)

instead, but it still worked correctly.

Thanks!

JP Verkamp

On Thu, Aug 25, 2011 at 2:38 PM, Jamison Hope <jrh@theptrgroup.com> wrote:
> 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
>> fine.
>>
>> 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 forms).
>>
>> Is there something I'm doing wrong / should be doing to make this work?
>>
>> Thanks ahead of time for any assistance.
>
> I'm not sure why that doesn't work, but I'm guessing that the one-argument
> eval isn't using the right Environment. Try this instead:
>
> ? ?Scheme.registerEnvironment();
> ? ?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.
>
> --
> Jamison Hope
> The PTR Group
> www.theptrgroup.com
>
>
>
>


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