In The Scheme Programming Language by Kent Dybvig (4th edition) section 3.4, he describes very clearly what continuation passing style is. For the why he gives two reasons:
- pass more than one result to its continuation, because the procedure that implements the continuation can take any number of arguments.
- CPS also allows a procedure to take separate continuations ..., which may accept different numbers of arguments.
Since the first reason can also be done using the values
procedure and the second using case-lambda
, I'm not clear the advantages of using continuation passing style. Could someone show me some examples of where continuation passing style is appropriate, where it makes the code better, clearer, etc.?
转载于:https://stackoverflow.com/questions/8544127/why-continuation-passing-style