CPS and Tail Calls
Note that in CPS, there is no implicit continuation — every call is a tail call. There is no "magic" here, as the continuation is simply explicitly passed. Using CPS without tail call optimization (TCO) will cause not only the constructed continuation to potentially grow during recursion, but also the call stack. This is usually undesirable, but has been used in interesting ways - see the Chicken Scheme compiler. As CPS and TCO eliminate the concept of an implicit function return, their combined use can eliminate the need for a run-time stack. Several compilers and interpreters for functional programming languages use this ability in novel ways.
Read more about this topic: Continuation-passing Style
Famous quotes containing the words tail and/or calls:
“Who is going to raise the dogs tail if he doesnt do it himself?”
—Estonian. Trans. by Ilse Lehiste (1993)
“I shun father and mother and wife and brother when my genius calls me. I would write on the lintels of the door-post, Whim. I hope that it is somewhat better than whim at last, but we cannot spend the day in explanation.”
—Ralph Waldo Emerson (18031882)