学习笔记:Continuation-passing Style
说来惭愧,虽然对于 CPS transform
这个概念略有耳闻(当时的理解是一种将普通递归调用变化为尾递归的方法),但是对于 CPS
这个概念还是在看轮子哥的文章 时才想起去详细了解。终究还是CS基础不牢。
Definition
In functional programming, continuation-passing style (CPS) is a style of programming in which control is passed explicitly in the form of a continuation. This is contrasted with direct style, which is the usual style of programming. Gerald Jay Sussman and Guy L. Steele, Jr. coined the phrase in AI Memo 349 (1975), which sets out the first version of the Scheme programming language.[1][2] John C. Reynolds gives a detailed account of the numerous discoveries of continuations.[3]
简单来说,就是一种程序调用方式,在每次函数调用时通过传参决定下一步执行的内容。