Assigning the result of a function to a variable will lead to the possibility of tail optimization?

Whenever I have a function to call at the end of another, I always call it on the same line as return, for example return foo(x).

Would assign the result of the variable botch any tail optimization opportunity? Like this,

function(...)
    ...
    tmp = foo(x)
    return tmp
end
+4
source share
1 answer

From http://www.lua.org/pil/6.3.html : In Lua, only a call in the format return g(...) is a tail call..

So, in this case, you do not have enough tail call optimization yes.

+5
source

Source: https://habr.com/ru/post/1530549/


All Articles