[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Firstclass continuations
Date: Wed, 25 May 88 23:10:12 EDT
From: Jonathan A Rees <JAR@AI.AI.MIT.EDU>
Date: Mon, 23 May 88 22:55:49 edt
From: jinx at CHAMARTIN.AI.MIT.EDU (Guillermo J. Rozas)
MIT Scheme has a procedure (rather than a special form) called
DYNAMIC-WIND, which is a generalization of UNWIND-PROTECT.
T has this too; it's called BIND-HANDLER, and behaves the same way.
(UNWIND-PROTECT body . exit) is sugar for (BIND-HANDLER FALSE (LAMBDA ()
body) (LAMBDA () . exit)). The BIND macro is also sugar for a use of
BIND-HANDLER, thus the name.
Okay, well, that's certainly a reasonable approach. To those who
aren't sure what we're talking about, consider the following example
(which I just ran in T 3.1):
> (define *x* 3)
3
> (define *saved-cont* 'nil)
NIL
> (define (test1)
(bind ((*x* 4))
(call-with-current-continuation
(lambda (c) (set *saved-cont* c)))
(print *x* (terminal-output))))
#{Procedure nn TEST1}
> (test1)
4 ;; printed by PRINT
;no value
> *x*
3 ;; as you'd expect
> (*saved-cont*)
4 ;; printed by PRINT
;no value
That is, the dynamic binding of *X* is restored when the continuation
saved in *saved-cont* is invoked. I did a further experiment that
verified that if more than one BIND-HANDLER is in force at the time a
continuation is gotten hold of, then when that continuation is
reinvoked, the entry-functions are called in the same order in which
they were called originally.
-----
Okay, well, it's nice to know how that works, and I agree it's pretty
sensible, but I want to say I have little inclination to use it,
especially in light of the fact that T specials are shallow-bound, so
that invoking a continuation which has lots of BINDs in it starts to
be a lot like a Zetalisp stack group switch. Yuck.
Also, this only answered one of my questions, and not the most
interesting one either, I think. What I would really like to hear
about is people's thoughts about eliminating the distinction between
CATCH and CALL-WITH-CURRENT-CONTINUATION (aka CALL/CC).
-- Scott