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.

-Brent

-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br]On Behalf Of Ben
Sunshine-Hill
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.

Ben

On 8/23/05, Brent Arias <barias@signaturedevices.com> wrote:
> In the manual here: http://www.lua.org/pil/9.3.html
>
> 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
on
> 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
>
>