lua-users home
lua-l archive

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


> 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

But this one works :)

> function always(x) return function() return x end end
> function add(i, j) return (i == 0 and always(j) or add)(i - 1, j + 1) 
end
> =add(1, 1000000)
1000001