Bookmark

OpenURL

Abstract

Numerous high-level control operators, with various properties, exist in the literature. To understand or compare them is difficult since their definitions use quite different theoretical frameworks; moreover, to our knowledge, no implementation offers them all. This paper tries to explain control operators by the often simple stack manipulation they perform. We therefore present what we think these operators are, in an executable framework derived from abstract continuations. This library is published in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For instance, we do not claim our implementation to be faithful nor we attempt to formally derive these implementations from their original definitions. The goal is to give a flavor of what control operators are, from an implementation point of view. Last but worth to say, all errors are mine. Among the many existing control operators, w...

Citations

...s, restrict the possibility of introspection which is the basis of reflective programming [dRS, FW84, Wan86, dR87, WF88, DM88]. 2 To compile well these closures requires a higher compiling technology =-=[App92]-=-. 3 This is true only if the user can submit such a definition and prevent the evaluator to CPS-convert it. 4 We use our own home-made object system called MeroonV3, consult again the Scheme repositor...

...e., multiple values are returned to the same continuation. This can be used by generators `a la Icon [MH90] but also appears in presence of concurrency [QD93]. The definition of call/cc as defined in =-=[CR91]-=- and according to ACPS, is as simple as it was according to CPS. Observe the duplication of q1 which is still the current continuation of the call to f as well as a part 3 of the reified continuation....

...plies its sole argument on it, the value of this application becomes the value of the original call/cc form. call/cc can be used to program any sequential control operator and, at least, multitasking =-=[Wan80]-=-, engines [HF84], escapes [HFW84] and even partial continuations! From a more implementational point of view, three usages can be recognized: ffl escape operator: the continuation is only invoked once...

...ons people can play with in any plain Scheme system. Our defining process is two-fold: first, we use a program transformation making continuations apparent: Abstract Continuation Passing Style (ACPS) =-=[FWFD88]. ACPS is -=-somewhat similar to Continuation Passing Style (CPS) but confers a richer structure to continuations. ACPS represents continuations by lists of &quot;continuation slices&quot;. Implementors will recog...

...erence with the coding of call/cc. The programsis wrapped as: (let () (define (call/cc f) (shift pc (pc (f (lambda (v) (shift ignore-pc (pc v)) )))) ) (reset ) ) 7 spawn Hieb and Dybvig presented, in =-=[HD90]-=-, a new control operator called spawn. Although specified in presence of concurrency, spawn is useful even in the absence of multiple processes. We will only present a sequential version here. One of ...

...form i.e., to replacesby (prompt ) may thus have a non-local effect. Using multiple embedded control forms is difficult but can be done if some protocol is added around each prompt form as studied in =-=[SF90a]-=-. The call/cc operator can be defined with these operators. Given a programsnot using prompt, we can provide the call/cc facility, rewritingsas: (let () (define (call/cc f) 6 (control (lambda (pc) (pc...

...gument on it, the value of this application becomes the value of the original call/cc form. call/cc can be used to program any sequential control operator and, at least, multitasking [Wan80], engines =-=[HF84]-=-, escapes [HFW84] and even partial continuations! From a more implementational point of view, three usages can be recognized: ffl escape operator: the continuation is only invoked once and only while ...

...e value of this application becomes the value of the original call/cc form. call/cc can be used to program any sequential control operator and, at least, multitasking [Wan80], engines [HF84], escapes =-=[HFW84]-=- and even partial continuations! From a more implementational point of view, three usages can be recognized: ffl escape operator: the continuation is only invoked once and only while in the dynamic ex...

...fine (call/cc f) (lower (lambda (pc) (pc (f (lambda (v) (lower (lambda (ignore) (pc v))) ))) )) )s)) 8 splitter/abort/call/pc Another set of control operators was proposed by Queinnec and Serpette in =-=[QS91]-=- 5 . Their effect is very close to spawn although one goal was to separate the different effects involved by spawn into different operators. splitter marks a context up to which partial continuations ...

...se is when a continuation is multiply invoked i.e., multiple values are returned to the same continuation. This can be used by generators `a la Icon [MH90] but also appears in presence of concurrency =-=[QD93]-=-. The definition of call/cc as defined in [CR91] and according to ACPS, is as simple as it was according to CPS. Observe the duplication of q1 which is still the current continuation of the call to f ...

...once and only while in the dynamic extent of the call/cc form that created it. This usage provides a setjmp/longjmp facility `a la C, catch/throw and variants `a la Common Lisp, call/ep `a la PaiLisp =-=[IM89]-=- etc. ffl coroutine operator: the computation is reified into a continuation, which will be invoked at most once later. An example of coroutine scheduler appear in [Wan80, Mat92]; ffl the last case is...

...ontinuations, partial continuations return a value and therefore can be composed. A partial continuation is a &quot;continuation slice&quot; which may be viewed as the &quot;difference&quot; of two re=-=gular continuations [MQ93]-=-. A partial continuation is thus identified by two points in a stack and all partial continuation control operators offer the three following functionalities: 1. to identify where a partial continuati...

...scheduler appear in [Wan80, Mat92]; ffl the last case is when a continuation is multiply invoked i.e., multiple values are returned to the same continuation. This can be used by generators `a la Icon =-=[MH90]-=- but also appears in presence of concurrency [QD93]. The definition of call/cc as defined in [CR91] and according to ACPS, is as simple as it was according to CPS. Observe the duplication of q1 which ...

...in [FFDM87, FFDM87, FF87] as well as in [Joh87, JD88]. Many papers follow in the Scheme realm and among them [Fel88, DF90, HD90, QS91, MQ93]. A detailed example of partial continuation use appears in =-=[Dan89]-=-. 4 Useful functions We introduce some functions to ease the forthcoming definitions. extend* takes a list of frames whereas extend takes only one frame. The split operator takes a continuation q, a p...

...es and to the received value. This tightly mimics the behavior of a frame that receives a value and has access to the frames that are below it. The ACPS program transformation appears in table 1, see =-=[Que92b]-=- for a variant. Computations are split into small atomic computation steps. A computation step is fed with a value and a continuation, may extend the continuation with new computations to be done or j...

...e done or just gives a value back to the continuation. Making frames apparent allows some compile-time analyzes to compact the continuation or to remove some kinds of associatively wrapped recursions =-=[Que93]-=-. ACPS-transformed programs contain a lot of administrative redexes: elaborate algorithms [DF92, SF92] can be devised to avoid their generation. One can also observe that CPS may be recovered from ACP...