3 ms·
the following is also tailcall: x = f(a) ... ... return x
by nabla9 8y ago
the following is also tailcall:
x = f(a)
...
...
return x
- tonyg 8y agoThat's not right, unless the "... ..." is empty, and even then, it depends on whether x is a global variable, and even if it isn't, it depends on the language.
- steinuil 8y agoThat's definitely not a tail call, and even with a smart compiler it's pretty hard that it would get optimized into "return f(a)". If "x" is declared there and never mutated in the subsequent code, and the code in the "..." doesn't perform any side effects, then such an optimization could occur... but then again, if the code in the "..." in your example didn't perform any side effects, it'd be dead code.
- nabla9 8y agoBetter examples: Both If (b == 3): x = f(a) else: x = g(a) return x and if (b == 3): x = f else: x = g return x(a) are equivalent to: if (b == 3): return f(a) else: return g(a) In every example the function call is in the tail position semantically. In the the two cases syntactically. The loop construct is hidden.