control.ss: Control Operators
To load: (require (lib "control.ss"))
This library provides various control operators from the literature on
higher-order control operators. These control operators are implemented
in terms of MzScheme's prompt and continuations (see section 6.5 in PLT MzScheme: Language Manual),
and they generally work sensibly together. For example, reset
and shift are aliases.
( SYNTAX
% expr [handler-expr])
See Sitaram, ``Handling Control,'' Proc. Conference on Programming Language Design and Implementation, 1993.
The essential reduction rules are:
(%obj proc) => obj (%E[(fcontrolobj)] proc) => (proc obj (lambda (x) E[x])) ; whereEhas no%
When handler-expr is omitted, % is the same as
prompt.
( SYNTAX
prompt expr ···1)
( SYNTAX
control identifer expr ···1)
See Felleisen, Wand, Friedman, and Duba, ``Abstract Continuations: A Mathematical Semantics for Handling Full Functional Jumps,'' Proc. Conference on LISP and Functional Programming, 1988. See also Sitaram and Felleisen, ``Control Delimiters and Their Hierarchies,'' Lisp and Symbolic Computation, 1990.
The essential reduction rules are:
(promptobj) => obj (promptE[(controlk expr)]) => (prompt((lambda (k) expr) (lambda (v) E[v]))) ; whereEhas noprompt
( SYNTAX
prompt-at prompt-tag-expr expr ···1)
( SYNTAX
control-at prompt-tag-expr identifer expr ···1)
Like prompt and control, but using the specified prompt
tags:
(prompt-attag obj) => obj (prompt-attag E[(control-attag k expr)]) => (prompt-attag ((lambda (k) expr) (lambda (v) E[v]))) ; whereEhas noforprompt-attag
( SYNTAX
reset expr ···1)
( SYNTAX
shift identifer expr ···1)
See Danvy and Filinski, ``Abstracting Control,'' Proc. Conference on LISP and Functional Programming, 1990.
The essential reduction rules are:
(resetobj) => obj (resetE[(shiftk expr)]) => (reset((lambda (k) expr) (lambda (v) (resetE[v])))) ; whereEhas noreset
This library's reset and prompt and interchangable.
( SYNTAX
reset-at prompt-tag-expr expr ···1)
( SYNTAX
shift-at prompt-tag-expr identifer expr ···1)
Like reset and shift, but using the specified prompt
tags.
( SYNTAX
prompt0 expr ···1)
( SYNTAX
reset0 expr ···1)
( SYNTAX
control0 identifer expr ···1)
( SYNTAX
shift0 identifer expr ···1)
See Shan, ``Shift to Control,'' Proc. Workshop on Scheme and Functional Programming, 2004.
The essential reduction rules are:
(prompt0obj) => obj (prompt0E[(control0k expr)]) => ((lambda (k) expr) (lambda (v) E[v])) (reset0obj) => obj (reset0E[(shift0k expr)]) => ((lambda (k) expr) (lambda (v) (reset0E[v])))
This library's reset0 and prompt0 and interchangable.
Furthermore, the following reductions apply:
(promptE[(control0k expr)]) => (prompt((lambda (k) expr) (lambda (v) E[v]))) (resetE[(shift0k expr)]) => (reset((lambda (k) expr) (lambda (v) (reset0E[v])))) (prompt0E[(controlk expr)]) => (prompt0((lambda (k) expr) (lambda (v) E[v]))) (reset0E[(shiftk expr)]) => (reset0((lambda (k) expr) (lambda (v) (resetE[v]))))
That is, both the prompt/reset and
control/shift sites must agree for 0-like
behavior, otherwise the non-0 behavior applies.
( SYNTAX
prompt0-at prompt-tag-expr expr ···1)
( SYNTAX
reset0-at prompt-tag-expr expr ···1)
( SYNTAX
control0-at prompt-tag-expr identifer expr ···1)
( SYNTAX
shift0-at prompt-tag-expr identifer expr ···1)
Variants that accept a prompt tag.
See Hieb and Dybvig, ``Continuations and Concurrency,'', Proc. Principles and Practice of Parallel Programming, 1990.
The essential reduction rules are:
(prompt-attag obj) => obj (spawnproc) => (prompttag (proc (lambda (x) (aborttag x)))) (prompt-attag E[(aborttag proc)]) => (proc (lambda (x) (prompt-attag E[x]))) ; whereEhas noforprompt-attag
See Queinnec and Serpette, ``A Dynamic Extent Control Operator for Partial Continuations,'' Proc. Symposium on Principles of Programming Languages, 1991.
The essential reduction rules are:
(splitterproc) => (prompt-attag (proc (lambda (thunk) (aborttag thunk)) (lambda (proc) (control0-attag k (proc k))))) (prompt-attag E[(aborttag thunk)]) => (thunk) ; whereEhas noprompt-atfortag(prompt-attag E[(control0-attag k expr)]) => ((lambda (k) expr) (lambda (x) E[x])) ; whereEhas noforprompt-attag
( SYNTAX
set prompt-expr expr ···1)
( SYNTAX
cupto prompt-expr identifier expr ···1)
See Gunter, Remy, and Rieke, ``A Generalization of Exceptions and Control in ML-like Languages,'' Proc. Functional Programming Languages and Computer Architecture, 1995.
In this library, new-prompt is an alias for
, make-continuation-prompt-tagset is an alias for
prompt0-at, and cupto is an alias for control0-at.