Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

18
  • 3
    That was a great historical insight, thank you! When I asked my question, I had indeed continuations in mind, especially continuation-passing style (CPS). In that case, a stack is not only inconvenient, but probably not necessary: you do not need to remember where to return, you provide a point where to continue your execution. I wondered if other stack-less approaches where common, and you gave some very good ones I was not aware of. Commented Jun 7, 2013 at 14:16
  • Slightly related: you correctly pointed out "if the language does not allow recursion". What about language with recursion, in particular functions that are not tail-recursive? Do they need a stack "by design"? Commented Jun 7, 2013 at 14:18
  • "Call stacks are only necessary in languages that allow recursion or mutual recursion" - no. If a function can be called from more than one place (e.g. both foo and bar may call baz), then the function needs to know what to return to. If you nest this "who to return to" information, then you end up with a stack. It doesn't matter what you call it or if it's supported by the CPU's hardware or something you emulate in software (or even if its a linked list of statically allocated entries), it's still a stack. Commented Jun 7, 2013 at 14:49
  • 1
    @AvivCohn: No. Read the other comments. Read specifically the descriptions of the CDC 6600 RJ instruction and the PDP-8 JMS instruction. HAVING SAID THAT, it is abundantly clear in the Real World that supporting general recursion is a Good Thing, and, for that, you do need something with call stack semantics. You either support recursion directly, or the programmer gets to simulate it. (The code to do this is MESSY. If you can find it, read the CDC 6600 STARTRK game PHOTON subroutine, and look at the simulated recursion for 8-way connectivity for nova triggering.) Commented Apr 20, 2020 at 12:12
  • 1
    @NicholasHumphrey I looked. Whoever did that code moved the 8-way nova connectivity logic into a separate SUBROUTINE NOVA. IT was inline in PHOTON on the version I worked on. Commented Sep 10, 2023 at 20:00