See https://news.ycombinator.com/item?id=31416448
def f() =
g()
In a language implementation that doesn't optimize tail calls, the stack would look like the following after the call to g: g
f
main
In a language implementation that does optimize tail calls, the stack would look like this, because the result of f is whatever the result of g is so f is no longer needed: g
main
If a language implementation doesn't optimize recursive tail calls, the following code will quickly overflow the stack and the program will crash: def loop() =
do something...
loop()
In a language implementation that does optimize recursive tail calls, this code can run forever because loop's stack frame gets replaced with the stack frame of the new call to loop.