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:
“And how do you know that youre mad?
To begin with, the Cat said, a dogs not mad. You grant that?
I suppose so, said Alice.
Well then, the Cat went on, you see a dog growls when its angry, and wags its tail when its pleased. Now I growl when Im pleased, and wag my tail when Im angry. Therefore Im mad.”
—Lewis Carroll [Charles Lutwidge Dodgson] (18321898)
“Whoever wont fight when the President calls him, deserves to be kicked back in his hole and kept there.”
—Lyndon Baines Johnson (19081973)