lua-users home
lua-l archive

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


PA wrote:

> This is a gratuitous deviation from how I invoked
> functions: always use parenthesizes.

But you don't want to invoke the function here, you want to
give it to Lua so that Lua can invoke it the appropriate
number of times, with the appropriate arguments.

This is indeed different from, for instance, C.  In C, you
can write a bit of code ("i++", for instance) to control
your loop variable(s) and put that code right in the third
for-expression, where it will get executed once every
iteration.  In Lua, you write a bit of code to control your
loop variable(s) and put it in a function, and then hand
that function itself to Lua.  The advantage of this is that
it allows the relevant code to be generated at runtime
(e.g., by using a closure).

As Rici pointed out, the appropriate thing to compare this
to is higher-order functions such as table.sort.

-- 
Aaron