lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Ok, yes, I figured that was what was happening.  However, I don't understand
why.  What inspired Lua, fortunately, to not evaluate the perm{"a", "b",
"c"} expression over and over again?

Knowing the answer, namely of Lua's calling logic, would make me a better
overall user of lua.


-----Original Message-----
[]On Behalf Of Ben
Sent: Tuesday, August 23, 2005 1:43 PM
To: Lua list
Subject: Re: call logic

There's no magic. The expression 'perm{"a", "b", "c"}' is evaluated,
and its result (the unnamed function which is returned by
coroutine.wrap) is used as the generator function for the for-block.


On 8/23/05, Brent Arias <> wrote:
> In the manual here:
> The following wrapped coroutine is demonstrated:
>    for p in perm{"a", "b", "c"} do
>      printResult(p)
>    end
>    function perm (a)
>      local n = table.getn(a)
>      return coroutine.wrap(function () permgen(a, n) end)
>    end
> What I don't understand, is what principle or rule of lua is preventing
> perm{"a","b","c"} to get called over and over again.  I mean, evidently
> "perm" is only called once, and the coroutine is the only part that keeps
> executing after the initial call to "perm."  I would have thought that
> "perm" would get called over and over as well, causing this loop to never
> end (or the coroutine.wrap to be executed over and over again).
> What magic is at work here?
> -Brent