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[(fcontrol
obj)] proc) => (proc obj (lambda (x) E[x])) ; whereE
has 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:
(prompt
obj) => obj (prompt
E[(control
k expr)]) => (prompt
((lambda (k) expr) (lambda (v) E[v]))) ; whereE
has no
prompt
(
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-at
tag obj) => obj (prompt-at
tag E[(control-at
tag k expr)]) => (prompt-at
tag ((lambda (k) expr) (lambda (v) E[v]))) ; whereE
has nofor
prompt-at
tag
(
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:
(reset
obj) => obj (reset
E[(shift
k expr)]) => (reset
((lambda (k) expr) (lambda (v) (reset
E[v])))) ; whereE
has no
reset
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:
(prompt0
obj) => obj (prompt0
E[(control0
k expr)]) => ((lambda (k) expr) (lambda (v) E[v])) (reset0
obj) => obj (reset0
E[(shift0
k expr)]) => ((lambda (k) expr) (lambda (v) (reset0
E[v])))
This library's reset0
and prompt0
and interchangable.
Furthermore, the following reductions apply:
(prompt
E[(control0
k expr)]) => (prompt
((lambda (k) expr) (lambda (v) E[v]))) (reset
E[(shift0
k expr)]) => (reset
((lambda (k) expr) (lambda (v) (reset0
E[v])))) (prompt0
E[(control
k expr)]) => (prompt0
((lambda (k) expr) (lambda (v) E[v]))) (reset0
E[(shift
k expr)]) => (reset0
((lambda (k) expr) (lambda (v) (reset
E[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-at
tag obj) => obj (spawn
proc) => (prompt
tag (proc (lambda (x) (abort
tag x)))) (prompt-at
tag E[(abort
tag proc)]) => (proc (lambda (x) (prompt-at
tag E[x]))) ; whereE
has nofor
prompt-at
tag
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:
(splitter
proc) => (prompt-at
tag (proc (lambda (thunk) (abort
tag thunk)) (lambda (proc) (control0-at
tag k (proc k))))) (prompt-at
tag E[(abort
tag thunk)]) => (thunk) ; whereE
has noprompt-at
fortag
(prompt-at
tag E[(control0-at
tag k expr)]) => ((lambda (k) expr) (lambda (x) E[x])) ; whereE
has nofor
prompt-at
tag
(
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-tag
set
is an alias for
prompt0-at
, and cupto
is an alias for control0-at
.