Hacker News new | ask | show | jobs
by travv0 1608 days ago
I'm not sure, so here are a couple examples.

    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.

The reason people want recursive tail calls optimized out is at a much higher level than anything to do with the actual CPU instructions being used, they just want to have a way to write recursive functions without worrying about the stack overflowing.

What's my age group, by the way?