[plt-scheme] almost automated cps transforms for web apps

From: kanishka (nish2575 at yahoo.com)
Date: Thu May 24 09:57:47 EDT 2007

forgive my ignorance if this has already been discussed in detail, or
if i'm using the terms incorrectly. did a search on gmane archive and
didn't find anything very relevant. 

in autmoatically restructing programs paper, it walks through the
process of transforming a scheme function, lambda lifting,
defunctionalization, ...

now, i may be a little over paranoid in resource utilization, but my
ideal continuation style web app would define two co-routines, a scheme
routine, and a javascript routine, and pass the continuation back and
forth, with no continuations actually stored on the server. it would
also allow for the javascript routine to branch to different
continuations (or pick another partner for its coroutine dance),
similar to what send/suspend/dispatch allows you to do. 

i'm doing all of this by hand right now. i've got a simple servlet that
allows a user to enter data, validates it, and performs an action. it
also allows a user to branch off into starting another continuation in
another servlet. some ( liberal (: ) pseudo code for the original
interactive function: 

(define (showForm msg)
   (let*
       loop
       ((f (make-form msg))
        (action 
K1------->
                (send (f 'outputhtml) (f 'outputjs))))
       (if (exit? action)
           (showForm "")

           (if (ok? action)

               (let ((result (process action)))
                  (showForm result))

               (let ((error (problem-with action))
                     (f (make-form msg action-data))
                     (action
K2------>
                          (send (f 'outputhtml) (f 'outputjs))))
                 (loop f action))
...
)


inside of make-form (which gets its data, generates a bunch of html), i
also generate my javascript co-routine. picture the javascript routine
as event handling loop for the web page. when it receives one of the
"submit" events, it appends the continuation point along with
serialized data to the request and sends the request. some pseudo code:


(define (make-js-continue data)
(emit-js-format 
"
function make_global_event_handler(){
   this.originalData = ~a;    

   this.handle = function(event){
        if( event == "minimizewindow" )
            change some css properties
        else if ( ... )
            ...
        else if( event == "submit")
            url = getSelectedContinuationName() + serialize();
            location.href = url;
        else ...
   }
}
var f = new make_global_event_handler();
register_handler(f.handle);
"
data
)
)

i have some code for the plumbing of continuing, resuming, and
marshalling on the server and client side.

how would one go about automatically generating closures for K1 and K2
given an arbitrary interactive function? i can picture some combination
of lambda lifting and then naming or storing the closure in a hash
table.  the paper references being able to do this. is there a simple
method, or am i walking down the path of compilation techniques...

spent some time thinking about letcc. but that only seems helpful in
generating runtime continuations, not closures.


      ____________________________________________________________________________________
Park yourself in front of a world of choices in alternative vehicles. Visit the Yahoo! Auto Green Center.
http://autos.yahoo.com/green_center/ 


Posted on the users mailing list.