[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Ah, those uninitiated people...
- From: David Kastrup <dak@...>
- Date: Wed, 13 Jan 2010 17:09:44 +0100
Tony Finch <dot@dotat.at> writes:
> On Wed, 13 Jan 2010, 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.
>
> What I meant was how to represent the coupling between the instruction
> pointer and the program state in the source code. You can represent
> each state as a function so that state transitions are tailcalls.
But that often causes contortions as well. You gain a lot more
expressive power if "state transitions are calls" merely. Sometimes it
is not easy to arrange for a call to get tail.
> If C supported tail calls, then I could implement each state as a
> function, state transitions as tail calls, and nesting as a normal
> function call. No need for a trans_table[], no process() loop, and no
> need for an explicit ifstate[] array of nested states.
But nesting does not work as a tail call, so you can't save the state
between state machine invocations.
--
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..., Tony Finch