Tail
_Tail_
_tail_
This collection provides one file:
_tail.ss_: special form for tail-context continuations
This library provides a syntax for capturing a continuation and binding it to a
variable that, when applied, evaluates its subexpression in tail position with
respect to its parent expression.
======================================================================
> (let-tail-continuation k body1 body2 ...)
> (let/tc k body1 body2 ...)
A syntax for capturing the current continuation and binding it to the variable
k. The variable is in scope for the evaluation of the body expressions. The
difference between _let/tc_ and _let/cc_ is that the argument to an
application of the continuation variable bound by _let/tc_ occurs in
tail position.
Continuations bound by _let/tc_ may only receive exactly one value.
> (push-begin e1 e2 ...)
A syntax for evaluating a sequence of expressions, like Scheme's
primitive BEGIN, but without preserving tail context. In particular,
the last expression of _push-begin_ is NOT in tail position with
respect to the containing expression.
The value of a _push-begin_ expression, like BEGIN, is the value of
the last expression in the sequence.
The expressions of a _push-begin_ may evaluate to multiple values (or
no values).
======================================================================
EXAMPLES -------------------------------------------------------------
(define (current-continuation-mark-list key-v)
(continuation-mark-set->list (current-continuation-marks) key-v))
(define (countdown n)
(with-continuation-mark 'countdown n
(let/ec return
(if (zero? n)
(return (current-continuation-mark-list 'countdown))
(return (countdown (sub1 n)))))))
> (countdown 10)
(0 1 2 3 4 5 6 7 8 9 10)
(define (countdown* n)
(with-continuation-mark 'countdown n
(let/tc return
(if (zero? n)
(return (current-continuation-mark-list 'countdown))
(return (countdown* (sub1 n)))))))
> (countdown 10)
(0)