4 ms·
Structured looping constructs are rather removed from how a machine works - not that this is inherently a bad thing. The way it actually works in a physical mac
by catnaroek 9y ago
Structured looping constructs are rather removed from how a machine works - not that this is inherently a bad thing. The way it actually works in a physical machine is via jumps into code that has already run, i.e. self-reference, i.e. recursion.
- adrianratnapala 9y agoMy way of saying the same thing is that there is surprisingly little difference between the recursive and iterative models when you start breaking things down. Indeed, if I were to add an explicit tail syntax to some language, it would probably involve the "goto" keyword.
- ajross 9y agoA loop can be turned into branch-based code with an absolutely trivial transformation (e.g. evaluate the test, branch to the end if false, branch back to the start at the end), I don't quite know what you mean by that. 3GL compilers were available with working looping syntax within years of the first programmable computers. FIVE decades later, and as this thread proves, we still don't have general algorithms to turn recursive solutions into iterative ones at the compiler level. It's true that it's more abstracted than machine code. It's absoultely not true that it's equivalently complicated to tail recursion detection.
- catnaroek 9y ago> It's absoultely not true that it's equivalently complicated to tail recursion detection. Tail recursion doesn't need to be “detected”. The correct implementation of all tail calls, recursive or otherwise, is to overwrite the current activation record, rather than save it.