• @sacredfire
    link
    3
    edit-2
    4 months ago

    I thought Tail recursion just gets turned into an iterative loop by the compiler? Hence why you won’t get a stack overflow. And since in procedural languages you can just use a loop in place of a tail recursive function you would never run into this problem, right? At least this is how it was taught to me when I was learning about it in lisp.

    • @[email protected]
      link
      fedilink
      34 months ago

      Yes you still need the loop part I skipped over that one, only focussing on the “why no return address on the stack” part. It’s what you need to focus on to see whether a recursive call is in a tail position and if it is the compiler does the rest no need to worry about that part.