[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Ah, those uninitiated people...
- From: David Kastrup <dak@...>
- Date: Thu, 14 Jan 2010 17:05:06 +0100
Jorge <xxopxe@gmail.com> writes:
> On Wed, 2010-01-13 at 15:44 +0100, David Kastrup wrote:
>> Wesley Smith <wesley.hoke@gmail.com> writes:
>> >> Tail calls are good for state machines.
>> >> ftp://publications.ai.mit.edu/ai-publications/pdf/AIM-443.pdf
>> >
>> > I find coroutines more elegant.
>>
>> Yup. Nothing beats using the instruction pointer and dynamic state as
>> state variable.
>
> Ok, hit me with a spoon, can anyone post an example of using
> coroutines to implement a state machine?
Uh, the posting you replied to contained an example right after the part
you quoted. Let me fetch that spoon.
> I guess each state is a coroutine, and transitions are yields and
> resumes, but the details escape me.
No, the whole "state machine" is one coroutine. You just program the
control flow that is to be modelled by the state machine. Yield/resume
pairs are used to get new input, and the input is processed with normal
conditionals and other branches. Every code path containing a yield
call corresponds to a state.
--
David Kastrup
- References:
- Ah, those uninitiated people..., Alexander Gladysh
- Re: Ah, those uninitiated people..., Enrico Colombini
- Re: Ah, those uninitiated people..., Roberto Ierusalimschy
- Re: Ah, those uninitiated people..., Andrew Wilson
- Re: Ah, those uninitiated people..., Mark Hamburg
- Re: Ah, those uninitiated people..., steve donovan
- Re: Ah, those uninitiated people..., David Given
- Re: Ah, those uninitiated people..., Tony Finch
- Re: Ah, those uninitiated people..., Wesley Smith
- Re: Ah, those uninitiated people..., David Kastrup
- Re: Ah, those uninitiated people..., Jorge