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:
“It is better to be the head of the chicken than the tail of an ox.”
—Chinese proverb.
“Not to find ones way in a city may well be uninteresting and banal. It requires ignorancenothing more. But to lose oneself in a cityas one loses oneself in a forestthat calls for a quite different schooling. Then, signboard and street names, passers-by, roofs, kiosks, or bars must speak to the wanderer like a cracking twig under his feet in the forest.”
—Walter Benjamin (18921940)