[racket] Engineering Tradeoffs of ANF transforms and the Stateless Server

From: Galler (lzgaller at optonline.net)
Date: Sat Dec 31 20:56:06 EST 2011

Sorry, should have included a brief example.

Here's an example of what I've implemented, which is just Harel's 
hierarchical state machines

You can create a Hierarchical State Machine by defining individual nodes 
in a flat file, as below.

each node has 6 keyword parameters , state, parent, entry, init, exit, 
and a handler.

The machine is very much like a web-server. It receives a signal (akin 
to a request), processes the signal which may cause a change internal 
state, and returns a continuation to be invoked when the next signal is 
presented.

The new signal is the argument provided to this continuation at 
invocation.

In the stateful server, the  HSM continuation is closed over by the PLT 
Server's external continuation (reified by send/suspend)

In the stateless version, I would replace the HSM continuation with the 
PLT server's continuation (reified by send/suspend).

I can't do that right now because the continuation is in the scope of 
the dynamic-wind function, which is an unsafe place to capture 
continuations for #lang web-server

The dynamic wind is used as follows:

At present, the nodes are brought into the correct tree-like dynamic 
extent by a recursive function which invokes dynamic-wind.

Note that the handler code supports jumping to another state  (trans 'S2 
'S3).

Trans invokes a continuation reified earlier associated with state S3. 
In this case, the invocation of the continuation calls the exit actions 
of state S2 and the entry actions of S3.

That's where the dynamic-wind comes in. Its necessary for transitions 
between states and but used for anything else.

That's why I think an overridden call/cc-dynamic-wind and dynamic wind 
would be sufficient.



(defnode
   #:state 'S2
   #:parent 'Top
   #:entry  (λ () (I-TLL:entry-start-TLL))
   #:init (lambda () (trans 'S2 'S3))
   #:exit  (λ () (I-TLL:exit-secure-TLL))
   #:handler (λ (signal)
               (cond
                 [(signal-eq? signal "main") (trans 'S2 'S3)]
                 [(signal-eq? signal "info") (trans 'S2 'S4)]
                 [(signal-eq? signal "about") (trans  'S2 'S5)]
                 [(signal-eq? signal "item") (trans 'S2 'S6)]
                 [(signal-eq? signal "field") (trans 'S2 'S7)]
                 [(signal-eq? signal "dispatch") (trans  'S2 'S8-3)]
                 [(signal-eq? signal "burden") (trans  'S2 'S8-2)]
                 [(signal-eq? signal "planning") (trans 'S2 'S8-1)]
                 [(signal-eq? signal "failentry") (trans 'S2 'S3)]
                 [else #f])))



Posted on the users mailing list.