[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] State machine using call/cc

From: felix winkelmann
Subject: Re: [Chicken-users] State machine using call/cc
Date: Wed, 8 Dec 2004 12:33:58 +0100

On Wed, 8 Dec 2004 12:21:17 +0100, felix winkelmann <address@hidden> wrote:

[Sorry, pressed the "send" button too early... (red ears)]

> Then (for example) the next-state procedure would save the
> current game state somewhere, together with the current
> continuation and return to the dispatcher:
(define (play-game game) this... that...
  (let ([request (next-state game)]) something else...
   ...) )

 (define (next-state game)
     (lambda (k)
       (game-continuation-set! game k)
       ((game-next-turn game) game) ) ) )

;;; this is probably called from C/C++:
(define (process-request req)
      (lambda (k)
          (game-next-turn-set! (request->game req) k)
          ((game-continuation (request->game req)) req) ) ) ) )

Well, this is probably pretty badly thought out, but you get
the idea: Each game saves it's current continuation in some
data structure (probably globally stored in a table) and
calling the "next-state" procedure will save the current continuation,
pass any information about the current state back to the dispatch-loop,
and is called again on the next request with the stuff sent by the
client - executing it's saved continuaton.

Sorry for the mess. Hope it helps a bit.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]