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.
“Our soul is cast into a body, where it finds number, time, dimension. Thereupon it reasons, and calls this nature necessity, and can believe nothing else.”
—Blaise Pascal (16231662)