This paper describes the transformation of -terms from continuation-passing style (CPS) to direct style. This transformation is the left inverse of Plotkin's left-toright call-by-value CPS encoding for the pure -calculus. Not all -terms are CPS terms, and not all CPS terms encode a left-to-right callby-value evaluation. These CPS terms are characterized here; they can be mapped back to direct style. In addition, the two transformations | to continuationpassing style and to direct style | are factored using a language where all intermediate values are named and their computation is sequentialized. The issue of proper tail-recursion is also addressed. Much work has been devoted to transforming programs into continuation-passing style (CPS). (For a recent survey, see Talcott's special issue on continuations 25].) In a CPS program, all procedures take an extra parameter | the continuation | which is a functional accumulator representing \the rest of the computation". As a consequence, all calls are tailcalls. By contrast, programs that are not in CPS (e.g., programs before CPS transformation) are said to be in \direct style" (DS). Their procedure calls can occur anywhere (i.e., not necessarily in tail position). In contrast to the work mentioned above, the present paper studies the transformation of CPS programs into DS. For brevity, only the pure (call-by-value, with left-to-right evaluation) -calculus is considered. A more thorough study (i.e., addressing conditional expressions, primitive operations, block structure, and recursive de nitions) is available in a technical report 7].
For instance, Danvy have studied relationship between the continuation passing style and the direct style REF .
Back to Direct Style
Sci. Comput. Program.
Computer Science