[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] State machine using call/cc
From: |
Joel Reymont |
Subject: |
Re: [Chicken-users] State machine using call/cc |
Date: |
Wed, 8 Dec 2004 12:20:34 +0000 |
> (define (next-state game)
> (call/cc
> (lambda (k)
> (game-continuation-set! game k)
> ((game-next-turn game) game) ) ) )
So in essence and if I understand this correctly, each state in the machine
needs to save its continuation once so that it can be re-entered. Right?
What if there is some data saved in the machine (continuation?) and
different states updated that. How would I ensure that they all got the
same continuation or will they get it automatically?
Lets assume that the data stored in the machine (game variables like a
list of players in the game) was the "context". I could do the state
machine by returning a pair of (data-to-be-sent . new-state-proc) from
the dispatcher but then I would always need to pass this context together
with the request/event into a state (proc) to get the next state.
The advantage of doing the same with continuations seems to be in that I
don't need to return the pair (data-to-be-sent . new-state-proc) from the
request dispatcher. I can just return the data-to-be-sent after saving
new-state-proc as a continuation. Then I would not need to pass the
context into new-state-proc when calling it with the next event as i
would retrieve this context as part of the continuation before calling
new-state-proc.
Am I correct in my thinking?
>;;; 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) ) ) ) )
If I had multiple state machines then I would also need to save each one
as a continuation it seems, right?
Joel
--
OpenPoker: The Linux of poker software
http://wagerlabs.com/forums
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
- Re: [Chicken-users] compile-time eval-time mismatch, felix winkelmann, 2004/12/08