This is the mail archive of the
kawa@sources.redhat.com
mailing list for the Kawa project.
RE: Compiling procedures questions
- From: "Crystal, Mayer" <mayer dot crystal at gs dot com>
- To: 'Per Bothner' <per at bothner dot com>
- Cc: "'kawa at sources dot redhat dot com'" <kawa at sources dot redhat dot com>
- Date: Tue, 28 Sep 2004 11:02:23 -0400
- Subject: RE: Compiling procedures questions
Per,
I've implemented your suggestions, but I am still ending up with the
same error. I've changed my code to use define instead of load and compiled
the procedure as you suggested. My compileRule method now looks like:
private static final Procedure compileRule( String rule ) throws Exception
{
...
String body = "( define (rule) " + rule + ")";
scheme.eval( body );
return (Procedure)scheme.eval( "rule" );
}
The code which uses this looks like:
1. String rule = "(or proc1? (or proc2? proc3?))";
2. Procedure proc = compileRule( rule );
3. return (Boolean)proc.apply0()
Unfortunately, line 3 still throws a ClassCastException - it still seems
that the result of proc.apply0() is returning an instance of my proc1 class
as opposed to the Boolean result I am expecting.
Thanks again,
Mayer
-----Original Message-----
From: Per Bothner [mailto:per@bothner.com]
Sent: Tuesday, September 28, 2004 1:51 AM
To: Crystal, Mayer
Cc: 'kawa@sources.redhat.com'
Subject: Re: Compiling procedures questions
Crystal, Mayer wrote:
> In other words, my code looks something like:
>
> 1. String rule = "(or proc1? (or proc2? proc3?))";
I'd recommend wrapping the rule in a function.
Scheme doesn't have the concept of evaluating a module -
e.g. "load" returns an undefined result. Yes, there are
ways in Kawa, but they're a bit more tricky, as the default behavior is to
ignore the values of top-level expressions.
String body = "(define (rule) (or ...))";
> 2. Procedure moduleBody = compileRule( rule );
> 3. return ((Boolean)moduleBody.apply0()).booleanValue();
;; Get the "rule" function in the Scheme global environment: Procedure rule
= scheme.eval("rule");
(Boolean) rule.apply0()
--
--Per Bothner
per@bothner.com http://per.bothner.com/