This is the mail archive of the kawa@sourceware.cygnus.com 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]

kawa question [forwarded]


[I forwarded this from Paul, because his site is listed as an
"open relay" by sourceware's anit-spam filter.  They are having
problems trying to properly configure sendmail ... --Per]

Hi all,

Trying to get out of here and go celebrate Valentine's day!

I am trying to use kawa as an embedded scripting language for use in a
program that generates interactive surveys.

Each screen in the survey allows you to go forward and backwards, and on
each screen, a particular answer plus any other arbitrary scripted
transaction can occur. Pretty simple.

When the survey is completed, all the transactions (bindings) are run
through in order, with the later bindings overwriting the early ones, and
you wind up with a final data set.

The rationale for the journalled file system is that you can go all the way
to the end of the survey, and then all the way back, effectively undoing all
the transactions that occurred on each question, and take a different path
through.

Let's say you answer question 1 of the survey. It resulted in adding a
transaction (binding) to our journalled file system, that binds the variable
name "vegHowHigh" to "PrettyHigh".

The journalled file system is essentially a LIFO that can also be revisited
in order and searched in reverse order. Actually, it is a LIFO of LIFOs: you
can save multiple transactions to a visit, then multiple visits to a
session.

When I get to question 2, it has a reference to question 1. I try to
evaluate an expression that has a reference to "vegHowHigh" like this:

    public Object execute(String aScript, session s, visit v) {
        Environment . setCurrent ( myInterpreter . getEnvironment () );
        try {
            return myInterpreter . eval ( aScript );
        }

the expression in question looks like this:

   (or (equal? VegHowHigh "VeryHigh") (equal? VegHowHigh "High"))

vegHowHigh is not bound in the current kawa environment, so I fault it in
from my journalled file system:

       catch ( kawa.lang.UnboundSymbol e ) {
            // our script contains an unknown variable "VegHowHigh"

            binding b = v . getAnswer ( e . symbol );
            // try visit, then session
            if ( b == null )
                b = s . getAnswer ( e . symbol );

This works great, I now have a simple binding object (name/value pair):
                
            myInterpreter . getEnvironment() . put ( b . getName (),
                b . getValue () );

This seems to work fine, and I can now look at myInterpreter in the
debugger, see its environ object, and the table in there, and it looks like
vegHowHigh was set up properly.

So now I try again:

            Object r = myInterpreter . eval ( aScript );
 
And I once again get an unbound symbol exception on "VegHowHigh."

Any ideas?

My hope was I could just do the eval and then clear the VegHowHigh binding
from the current environment like this:

            myInterpreter . getEnvironment() . remove ( b . getName () );
            return r;
        }

and then if I have to reference this variable in the future, I will again
look in the journalled file system of bindings and possibly find a later
version.

Any ideas?

Meta-question:

I know there is probably a better way to do this using closures or
continuations or some such, but my knowledge of Lispy languages is somewhat
minimal. 

I considered making my own chain of environments, one per question, with
environment chaining serving as a way of handling the searching backwards
through the journal for transactions, and trying to manage that myself, but
I'm not sure how I would chain on a new environment for each question in the
journalled file system and then "unwind." Environments might not take kindly
to that kind of handling? The docs seem a bit sketchy on points like this.
But maybe that would do what I want in the long run?

Thanks for suggestions.

Paul

-- 
"I put Sluggo in the sink and gave him some dog food rated 'for small dogs.'
The turtles are more fun if you think of them as very small, very wet dogs."
Paul R. Potts - Technology Group Leader - Health Media Research Lab
Comprehensive Cancer Center - University of Michigan - potts@umich.edu

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