Re: ANN: Etiquette: a protocol construction tool

Marco Baringer <[email protected]> Thu, 18 Sep 2003 19:17:16 +0200
Newsgroups gmane.lisp.clump
Message-ID <[email protected]>
Luke Gorrie <[email protected]> writes:

> Peter Seibel <[email protected]> writes:
>
> [... lots of good stuff ...]
>
>> it would be great to have a tool that lets me generate the protocol
>> state machine for an arbitrary protocol in such a way that I can
>> somehow plug in the actions it should do when it needs to interact
>> with the outside world (i.e. do potentially blocking i/o) and
>> provide some way to "suspend" the state machine and "continue" it
>> when the i/o completes.
>
> And to come full circle, this is why I posted the link to Steele's
> little interpreter for a Lisp with call/cc. If the state machine's
> execution engine is written in continuation-passing style, then it's
> easy to suspend/continue. When you need to suspend and wait for I/O
> you just grab the current continuation and pass it to the
> I/O-scheduler. When your I/O is ready and you want to resume you just
> call the continuation.

[shameless plug:]

I followed the same thought track when working with web apps and ended
up writing a code walker which cps transforms cl code. I initially
tried the interpreter route, but it appeared to be a lot more work
than transforming things and letting the underlying lisp deal with
optimizing it. 

Currently it works enough for me to be able to write:

(with-call/cc
  (progn
    (loop for user-info = (call-page 'get-reg-info)
          until (valid-registration-info user-info)
          finally do (create-new-user user-info))
    (call-page 'welcome-page)
    (goto-page 'home-page)))

Where call-page and goto-page are "blocking" calls. I find this to be
a major leap forward as far as web apps are concerned, but i haven't
really thought if this could be usefull for low level network
code. The transformation is fairly naive and currently implies a major
perfromance hit (~ 10x slower than hand rolled cps style code).

It doesn't pretend to handle all the code you want to write, but it's
Good Enough For Me (TM). anyways, you can get the code from the file
src/cps.lisp in
ftp://ftp.common-lisp.net/pub/project/bese/arnesi-latest.tar.bz2

-- 
-Marco
Ring the bells that still can ring.
Forget your perfect offering.
There is a crack in everything.
That's how the light gets in.
     -Leonard Cohen