• sacredfire@programming.dev
    link
    fedilink
    arrow-up
    3
    ·
    edit-2
    8 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.

    • barsoap@lemm.ee
      link
      fedilink
      arrow-up
      3
      ·
      8 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.