[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Proper tail recursion
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Thu, 26 Jul 2001 21:43:30 -0300
>Interesting. Well, how about an *optional* optimizer, which takes in Lua
>bytecode, looks for optimizations like that, and outputs the optimized
>bytecode. I don't know much about Lua internals... does that sound
The main point is that there are no such things as tail recursions, because
global names are resolved at runtime.
More precisely, in the code below
if a(x) then return b(x) end
By the time f runs and tries to call "itself", the called f might not even be
the original one because a(x) might have changed the value of the global f.
Not likely, but it just shows that the dynamic nature of Lua does make things
>Re: tail calls... can the decision be made at the time of the recursive
>call rather than at compile time?
Now, this could work and we actually discussed this once. We never added it
to the main code because it would ruin debugging, but would it really?
Moreover, it would not do anything for mutually recursive functions.