[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
R5RS
I have received numerous minor corrections to my previous
draft (4.97) of R5RS. It was also pointed out to me that
the description of DYNAMIC-WIND was unnecessarily vague.
In addition, there was a discussion on the author's list
on including a more explicit description of the requirement
for proper tail recursion.
A new description of DYNAMIC-WIND is at the end of this message.
I will send a proposal for the tail-recursion requirement in
a separate message.
Except for these two changes I am done with R5RS. I will
release the text and sources as soon as a consensus on them
is reached.
-Richard Kelsey
(dynamic-wind <before> <thunk> <after>) procedure
Calls <thunk> without arguments, returning the result(s) of this call.
<Before> and <after> are called, also without arguments, as required
by the following rules (note that in the absence of calls to continuations
captured using CALL-WITH-CURRENT-CONTINUATION the three arguments are
called once each, in order). <Before> is called whenever execution
enters the dynamic extent of the call to <thunk> and <after> is called
whenever it exits that dynamic extent. The dynamic extent of a procedure
call is the period between when the call is initiated and when it
returns. In Scheme, because of CALL-WITH-CURRENT-CONTINUATION, the
dynamic extent of a call may not be a single, connected time period.
It is defined as follows:
- The dynamic extent is entered when execution of the body of the
called procedure begins.
- The dynamic extent is also entered when execution is not within
the dynamic extent and a continuation is invoked that was captured
(using CALL-WITH-CURRENT-CONTINUATION) during the dynamic extent.
- It is exited when the called procedure returns.
- It is also exited when execution is within the dynamic extent and
a continuation is invoked that was captured while not within the
dynamic extent.
If a second call to DYNAMIC-WIND occurs within the dynamic extent of the
call to <thunk> and then a continuation is invoked in such a way that the
<after>s from these two invocations of DYNAMIC-WIND are both to be called,
then the <after> associated with the second (inner) call to DYNAMIC-WIND
is called first.
If a second call to DYNAMIC-WIND occurs within the dynamic extent of the
call to <thunk> and then a continuation is invoked in such a way that the
<before>s from these two invocations of DYNAMIC-WIND are both to be called,
then the <before> associated with the first (outer) call to DYNAMIC-WIND
is called first.
If invoking a continuation requires calling the <before> from one call
to DYNAMIC-WIND and the <after> from another, then the <after> is called
first.
The effect of using a captured continuation to enter or exit the dynamic
extent of a call to <before> or <after> is undefined.
(let ((path '())
(c #f))
(let ((add (lambda (s)
(set! path (cons s path)))))
(dynamic-wind
(lambda () (add 'connect))
(lambda ()
(add (call-with-current-continuation
(lambda (c0)
(set! c c0)
'talk1))))
(lambda () (add 'disconnect)))
(if (< (length path) 4)
(c 'talk2)
(reverse path))))
--> (connect talk1 disconnect connect talk2 disconnect)