lua-users home
lua-l archive

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


> So this is what tail calls are for. This means that there is no threat 
> of stack overflow in a state machine like you suggest, is there? I 
> certainly couldn't get stackoverflow in my quick test based on two 
> functions calling each other. No memory growth either! Very sweet.

That's the meaning of *proper* in "proper tail calls".  (Usually people
call this "proper tail recursion", I guess because it is kind of boring
without recursive calls.)

Notice that you only get this behavior when you do tail calls. In Lua,
this means "return f(...)".  None of these apparently equivalent forms
works:

  f(); return 
  return x, f()
  return x or f()

-- Roberto