Would assigning result from a function to a variable ruin an opportunity for tail optimization?

StackOverflow https://stackoverflow.com/questions/22243857

  •  10-06-2023
  •  | 
  •  

문제

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

Would assigning the result to a variable botch any possibility of tail optimization? Like this,

function(...)
    ...
    tmp = foo(x)
    return tmp
end
도움이 되었습니까?

해결책

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 are missing the tail call optimization yes.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top