lua-users home
lua-l archive

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


On Thu, 2 Sep 1999, Luiz Henrique de Figueiredo wrote:

> It might work for you, but this solution requires 2 variables external to
> the loop (endvalue and increment) -- but you say that this is A Good Thing.

That's not such a problem.  Most loops, I suspect, know when to end
and how to change the loop variable without variables from outside the
loop.  In any case, it would be similar with a while loop.  (Without the
upvalue syntax.)

> More seriously, you cannot assign to local variables inside the loop,
> only to global variables. This would be an ungly restriction for loops.
> Of course, you can always use a table as an upvalue and then assign fields
> of it inside the loop. That would work.

True.  That wouldn't be particularly elegant.  However, you can also
return a value with the return statement.  So you could have the initial
Loop() call set some local variables with the return values from the loop.

> About tail-recursion optimization, we already have an opcode for this.
> We just don't check whether we can re-use the stack.
> We'll be discussing this for the next version.

Tail recursion clearly isn't going to work everywhere.  However, I would
guess that it'll work in a lot more places than the current while loop. 

F