• Liked Ramakrishnan Muthukrishnan

    An introduction to Continuation Passing Style (CPS)

    Ramakrishnan Muthukrishnan
    Ramakrishnan Muthukrishnan
    schedule 2 years ago
    Sold Out!
    60 mins

    Traditionally functions return some value. Someone is waiting for that value and does some computation with it. This "someone" is called the continuation of this value. In a normal functional call, the continuation is "implicit". In the "continuation passing style" (hence forth called with the short form, CPS), we make the continuations explicit. In this style, function definitions take an extra argument called "continuation" and it never return. The "return value" of the function 'continues' by passing this value as an argument to the continuation. Continuations are sometimes called "gotos with arguments".

    CPS is used as an intermediate stage while compiling a program since it makes the control structure of the program explicit and hence can be converted easily to machine code. Another feature of a CPS-transformed function is that it is tail-recursive even if the original function was not written in a tail-recursive style.

    Continuations enable a programmer to build new control operators (if the language's built-in operators does not already provide the control operators the programmer need).

Sorry, no proposals found under this section.