[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Ah, those uninitiated people...
- From: Sean Conner <sean@...>
- Date: Thu, 14 Jan 2010 02:37:16 -0500
It was thus said that the Great Wesley Smith once stated:
> > It's not the same, though. Apart from having to reorder my logic to suit
> > the restrictions of the language, which is always a pain, there's a
> > performance hit in that shared state has to be accessed via upvalues
> > rather than locals, which are considerably more expensive --- not just
> > to access, but also to create individual closures for each state in your
> > state machine. Say you have a state-machine based parser for network
> > packets. You have two choices: construct and then discard potentially
> > hundreds of closures for every packet, or restructure the entire state
> > machine not to need shared state. One's slow, the other's inconvenient.
>
>
> Is that really true? I'm not sure I buy it. Why can't you use
> coroutines with locals and and infinite loop to implement your state
> machine? I've done this in many situations and have never had the
> need for upvalues.
Or just pass a table around to each state:
result = state1({})
function state1(info)
-- blah blah blah
return state2(info)
end
function state2(info)
-- yada yada
return state3(info)
end
function state3(info)
if info.blah then return "done" end
return state1(info)
end
-spc (But I could be missing something ... )
- References:
- 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
- Re: Ah, those uninitiated people..., David Kastrup
- Re: Ah, those uninitiated people..., Tony Finch
- Re: Ah, those uninitiated people..., David Kastrup
- Re: Ah, those uninitiated people..., Tony Finch
- Re: Ah, those uninitiated people..., David Given
- Re: Ah, those uninitiated people..., Wesley Smith