Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Considering what this has been compiled to, we have turned code that uses the call stack to implement recursion into code that does not (and in doing so turned code that will throw a stack-overflow exception for even quite small values into code that will merely take an excruciatingly long time to return [see How can I prevent my Ackerman function from overflowing the stack?How can I prevent my Ackerman function from overflowing the stack? for some further optimisations that make it actually return for many more possible inputs]).

Considering what this has been compiled to, we have turned code that uses the call stack to implement recursion into code that does not (and in doing so turned code that will throw a stack-overflow exception for even quite small values into code that will merely take an excruciatingly long time to return [see How can I prevent my Ackerman function from overflowing the stack? for some further optimisations that make it actually return for many more possible inputs]).

Considering what this has been compiled to, we have turned code that uses the call stack to implement recursion into code that does not (and in doing so turned code that will throw a stack-overflow exception for even quite small values into code that will merely take an excruciatingly long time to return [see How can I prevent my Ackerman function from overflowing the stack? for some further optimisations that make it actually return for many more possible inputs]).

added 2 characters in body
Source Link
Jon Hanna
  • 2.1k
  • 12
  • 15

If we strictly require it to involve the call-stack (whichor whatever mechanism for one thing assumes the existence of a call-stackmaintaining program state is used), then we can always replace it with something that doesn't. Indeed, languages that lead naturally to heavy use of recursion tend to have compilers that make heavy use of tail-call optimisation, so what you write is recursive but what you run is iterative.

If we strictly require it to involve the call-stack (which for one thing assumes the existence of a call-stack), then we can always replace it with something that doesn't. Indeed, languages that lead naturally to heavy use of recursion tend to have compilers that make heavy use of tail-call optimisation, so what you write is recursive but what you run is iterative.

If we strictly require it to involve the call-stack (or whatever mechanism for maintaining program state is used), then we can always replace it with something that doesn't. Indeed, languages that lead naturally to heavy use of recursion tend to have compilers that make heavy use of tail-call optimisation, so what you write is recursive but what you run is iterative.

added 181 characters in body
Source Link
Jon Hanna
  • 2.1k
  • 12
  • 15

Of course, all of this assumes you have a choice. There are both languages that prohibit recursive calls, and languages that lack the looping structures necessary for iterating.

Of course, all of this assumes you have a choice. There are both languages that prohibit recursive calls, and languages that lack the looping structures necessary for iterating.

Syntax hint. Nice name for raw url.
Source Link
user40980
user40980
Loading
added 1 character in body
Source Link
Jon Hanna
  • 2.1k
  • 12
  • 15
Loading
added 3 characters in body
Source Link
Jon Hanna
  • 2.1k
  • 12
  • 15
Loading
Source Link
Jon Hanna
  • 2.1k
  • 12
  • 15
Loading