• Subject: RE: call logic
• From: "Brent Arias" <barias@...>
• Date: Tue, 23 Aug 2005 14:46:31 -0700

Thanks!  :)

-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 2:21 PM
To: Lua list
Subject: Re: call logic

On 8/23/05, Brent Arias <barias@signaturedevices.com> wrote:
> 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.

I think perhaps the confusion here relates to the difference between a
C loop construct and a Lua loop construct. In C, of course, the test
for a for-loop is an expression that is evaluated before each
iteration through the loop. C doesn't have any concept of a lambda, so
that's really the only way to do it. The entirety of the loop-test
expression, in essence, is treated as a lambda.

Lua, however, does have the luxury of lamba functions. Instead of
evaluating an expression for each iteration, it calls the lambda
function it has been given. So when you think about a line like
'perm{"a", "b", "c"}', realize that the fact that a function call is
happening at all, is a red herring. There doesn't need to be a
function being CALLED, only a function RESULTING from the evaluation
of the expression. Evaluating the expression, in other words, is not a
part of iteration. It's as though you did something like "local x = 2
+ 3"... the VM does not add 2 and 3 each time you refer to x.

Ben