[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: SV: [ANN] Lua 5.2.0 (beta-rc2) now available
- From: David Given <dg@...>
- Date: Thu, 23 Jun 2011 13:46:49 +0100
Alex Queiroz wrote:
[...]
> You only need tail calls for state machines.
Depends on your requirements --- tail calls are, for example, absolutely
not an option for any of my stuff because they're too expensive.
The expense is not the tail call itself, mind, but the upvalues needed
to share data between states:
For example:
local function statemachine()
local i = 1
local j = 2
local state1
local state2
state1 = function() i = i + 1 return state2() end
state2 = function() j = j + 1 end
return state1()
end
...allocates at least four heap cells *every time* statemachine() is
called; don't forget, the state functions themselves are upvalues...
The only other option is to pass your shared data in and out of every
state. But that's incredibly messy and hard to write and it's *still*
slower than an honest goto.
--
┌─── dg@cowlark.com ───── http://www.cowlark.com ─────
│ "I have always wished for my computer to be as easy to use as my
│ telephone; my wish has come true because I can no longer figure out
│ how to use my telephone." --- Bjarne Stroustrup
Attachment:
signature.asc
Description: OpenPGP digital signature
- References:
- [ANN] Lua 5.2.0 (beta-rc2) now available, Luiz Henrique de Figueiredo
- Re: [ANN] Lua 5.2.0 (beta-rc2) now available, dcharno
- Re: [ANN] Lua 5.2.0 (beta-rc2) now available, Josh Simmons
- Re: [ANN] Lua 5.2.0 (beta-rc2) now available, David Manura
- Re: [ANN] Lua 5.2.0 (beta-rc2) now available, Lorenzo Donati
- Re: [ANN] Lua 5.2.0 (beta-rc2) now available, David Kastrup
- Re: [ANN] Lua 5.2.0 (beta-rc2) now available, Lorenzo Donati
- Re: [ANN] Lua 5.2.0 (beta-rc2) now available, Roberto Ierusalimschy
- SV: [ANN] Lua 5.2.0 (beta-rc2) now available, Fredrik Widlund
- Re: SV: [ANN] Lua 5.2.0 (beta-rc2) now available, Philippe Lhoste
- Re: SV: [ANN] Lua 5.2.0 (beta-rc2) now available, Alex Queiroz