Value Transforming Style
暂无分享,去创建一个
A new program transformation is presented that allows to remove control operators related to partial continuations. The basis for the transformation is to adopt an improved representation for continuations that makes frames apparent. Various examples of control operators with or without dynamic extent stress are presented. Scheme IEE91], ooers rst-class continuations with indeenite extent. Pioneered in Lan65, Rey72], continuations proved to be very useful tools allowing to program a wide variety of control features such as coroutines Wan80], engines HF84], escapes HFW84] etc. The call/cc function reiies Wan86] continuations into monadic functions, transfer of control occurs when these functional objects are applied. A transformation called \Continuation Passing Style" (or CPS for short) exists that transforms a program using call/cc into a new semantically equivalent program without call/cc. In this transformation, continuations are transformed again into monadic functions. CPS has been extensively studied, see DL92, SF92] for recent developments. CPS is also a programming style. A function written in CPS-style takes an extra argument known (mis!?)fortunately as the continuation. This continuation represents the nal receiver of the value computed by the function. This extra argument does not need to be a real continuation, an object built by call/cc, but can simply be a value transformer i.e.a regular monadic function without control eeect. Consider for instance the CPS-transformed factorial function: (define (cps-fact n k) (if (= n 1) (k 1) (cps-fact (-n 1) (lambda (r) (k (* n r)))))) One generally invokes this CPS-style cps-fact function as (cps-fact 5 (lambda (x) x)) rather than as (call/cc (lambda (k) (cps-fact 5 k))). This turns out to be psychologically important: people tend to view the k variable of cps-fact as holding a value transformer which is applied on the nal result rather than as an escape to the calling point of cps-fact with the nal value. Partial continuations are a new concept and allow to abstract over control. Several sets of control operators were proposed in FWFD88, DF90, QS91]: they emphasize diierent aspects and have various properties. Unlike regular continuations, partial continuations are real functions that return values: they thus can be composed and resemble more to value transformers. For instance and with the notations of QS91], the following factn function, given a number n, returns a function which will multiply its unique argument by the factorial of n: (define (finalizing-fact n terminator) (if (= n 1) (terminator 1) (* n (finalizing-fact (-n 1) …
[1] Mitchell Wand,et al. Continuation-Based Multiprocessing , 1980, High. Order Symb. Comput..