summaryrefslogtreecommitdiffstats
path: root/txr.1
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-10-28 20:18:20 -0700
committerKaz Kylheku <kaz@kylheku.com>2015-10-28 20:18:20 -0700
commita5ef086fc33cfbfce7b03bad291efa28acf739b2 (patch)
treeb6658f3ecbc98054217f72a166b02bfdb0b029e0 /txr.1
parent67af4be97a2ea8700a841feb893a1f1747987843 (diff)
downloadtxr-a5ef086fc33cfbfce7b03bad291efa28acf739b2.tar.gz
txr-a5ef086fc33cfbfce7b03bad291efa28acf739b2.tar.bz2
txr-a5ef086fc33cfbfce7b03bad291efa28acf739b2.zip
Implementing sys:abscond-from operator.
* eval.c (sys_abscond_from_s): New symbol variable. (op_abscond_from): New static function. (do_expand): Handle abscond-from like return-from. (eval_init): Initialize sys_abscond_from_s and register sys:abscond-from operator. * share/txr/stdlib/yield.tl (yield-from): Use sys:abscond-from instead of return-from, to avoid tearing down the continuation's resources that it may need when restarted. * txr.1: Documented sys:abscond-from and added a mention to the Delimited Continuations introduction. * unwind.c (uw_abscond_to_exit_point): New static function. (uw_block_abscond): New function. * unwind.h (uw_block_abscond): Declared.
Diffstat (limited to 'txr.1')
-rw-r--r--txr.155
1 files changed, 54 insertions, 1 deletions
diff --git a/txr.1 b/txr.1
index de1430f6..23958b86 100644
--- a/txr.1
+++ b/txr.1
@@ -27413,6 +27413,25 @@ and
which create an abstraction which models the continuation as a suspended
procedure supporting two-way communication of data.
+Continuations raise the issue of what to do about unwinding.
+The language Scheme provides the much criticized
+.code dynamic-wind
+operator which can execute initialization and clean-up code as
+a continuation is entered and abandoned. \*(TX takes a simpler,
+albeit risky approach. It provides a non-unwinding escape operator
+.code sys:abscond-from
+for use with continuations. Code which has captured a continuation
+can use this operator to escape from the delimiting block without
+triggering any unwinding among the frames between the capture point and the
+delimiter. When the continuation is restarted, it will then do so
+with all of the resources associated with it frames intact.
+When the continuation executes normal returns within its context,
+the unwinding takes place then. Thus tidy, "thread-like" use
+of continuations is possible with a small measure of coding discipline.
+Unfortunately, the absconding operator is dangerous: its use
+breaks the language guarantee that clean-up associated with a form is done no
+matter how a form terminates.
+
.TP* Notes:
Delimited continuations resemble lexical closures in some ways. Both
@@ -27548,6 +27567,37 @@ with named prompts.
--> 24
.cble
+.coNP Operator @ sys:abscond-from
+.synb
+.mets (sys:abscond-from < name <> [ value ])
+.syne
+.desc
+The
+.code sys:abscond-from
+operator closely resembles
+.code return-from
+and performs the same thing: it causes an enclosing block
+.meta name
+to terminate with
+.meta value
+which defaults to
+.codn nil .
+
+However, unlike
+.codn return-from ,
+.code sys:abscond-from
+does not perform any unwinding.
+
+This operator should never be used for any purpose other than
+implementing primitives for the use of delimited continuations.
+It is used by the
+.code yield-from
+and
+.code yield
+operators to escape out of a block in which a continuation has
+been captured. Neglecting to unwind is valid due to the expectation
+that control will return into a restarted copy of that context.
+
.coNP Macros @ obtain and @ yield-from
.synb
.mets (obtain << forms *)
@@ -27573,7 +27623,10 @@ are encapsulated in a special
Finally,
.code yield-from
performs a non-local transfer to the same block, so that the yield object
-appears as the result value of that block.
+appears as the result value of that block. The non-local transfer is
+performed abruptly, by the
+.code sys:abscond-from
+operator.
An
.code obtain