lua-users home
lua-l archive

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


It was thus said that the Great Roberto Ierusalimschy once stated:
> >   I don't know.  This
> > 
> > 	x = 5
> > 	function F(...)
> > 	  return F(x,...)
> > 	end
> > 
> > 	print(F())
> > 
> > is taking an awful long time to fail.

  By "long time to fail" I mean "it's stuck in an infinite loop."

> I believe this is O(n^2), as each new call copies all accumulated
> arguments. Change your function to this and you will see the
> slowdown:
> 
> local x = 0
> function F(...)
>   x = x + 1
>   print(x)
>   return F(x,...)
> end
> 
> print(F())

  I did that, and it's currently stuck (20 minutes) in an infinite loop.  

  -spc (Tail calls for the win!)