lua-users home
lua-l archive

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


>From lua-l@tecgraf.puc-rio.br Thu Sep  2 11:51:58 1999
>From: Fred Bertsch <fb@anise.ee.cornell.edu>

>Here's another possibility that wouldn't require extending the language at
>all.  If you add a tail-recursion optimization, you could make a loop look
>like this:
>
>local Loop = function( i )
>  [ loop code ]
>  if( i == %endvalue ) then
>    return
>  end
>  [ more loop code ]
>  Loop( i + %increment )
>end
>Loop( startvalue )

>That would give me everything I'd need.

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.
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.

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.
--lhf