lua-users home
lua-l archive

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


Alexander Gladysh wrote:
> > In theory, recursion (without varargs) could be optimized as well
> > as any loop. In practice, it probably won't. Simply because few
> > real-world Lua code makes use of recursion for time-critical parts.
> 
> Well, I planned to create visual flow-programming DSL with gotos (as
> links between commands), which would be translated to Lua code heavily
> abusing tail recursion...

Recursion and tail recursion are two completely different issues
for the compiler. Tail recursion is easy, this already works fine.
But 'true' recursion poses some difficulties, the down-recursive
part in particular.

> That is, probably, the only case where I can't see easy non-recursive
> alternative.

Don't worry. Tail recursion is fast -- use it!

> >> The question is: can LJ2 be made to optimize the function below away?
> >> (That's what args_unroll_simple is.)
> >>
> >>   local arguments = function(...)
> >>       local n = select("#", ...)
> >>       -- Assuming cache is pre-populated for all possible use-cases
> >>       return assert(arguments_cache[n])(...)
> >>   end
> 
> > Yes, I'm pretty sure this can be optimized away. The only thing
> > preventing it right now is the varag function and select().
> 
> So, you're saying that this optimization will most likely make it into
> LJ2 release?
> Can I start writing code in this way? :-)
> 
> Sorry for pushing you. If you can't say it now, I'll understand.

No guarantees. And I'm sorry, but there are more pressing issues
right now.

--Mike