[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)
...do this...
...do that...
(let ([request (next-state game)])
...do something else...
...) )
(define (next-state game)
(call/cc
(lambda (k)
(game-continuation-set! game k)
((game-next-turn game) game) ) ) )
;;; this is probably called from C/C++:
(define (process-request req)
(generate-response
(call/cc
(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.
cheers,
felix
Re: [Chicken-users] compile-time eval-time mismatch, Michele Simionato, 2004/12/08
- Re: [Chicken-users] compile-time eval-time mismatch, felix winkelmann, 2004/12/08
- Re: [Chicken-users] compile-time eval-time mismatch, Michele Simionato, 2004/12/08
- Re: [Chicken-users] compile-time eval-time mismatch, felix winkelmann, 2004/12/08
- Re: [Chicken-users] compile-time eval-time mismatch, Michele Simionato, 2004/12/08
- Re: [Chicken-users] compile-time eval-time mismatch, Michele Simionato, 2004/12/08