[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Scheme mistakes (was Re: nil)



>    From: "Alan Bawden" <Alan@lcs.mit.edu>
>    >
>    > Consider evaluating:
>    >
>    >   (throw (f x) 42)
>    >
>    > Since you know that the expression `(f)' must yield a continuation,
the
>    > old continuation can be discarded (and perhaps reclaimed by the
garbage
>    > collector) -before- you call the function `f'.

>    From: "Joe Marshall" <jrm@ccs.neu.edu>
>    Date: Thu, 14 Aug 2003 16:09:20 -0400
>
>    (throw (call-with-current-continuation (lambda (c) ...)) 42)
>
> What about it?  In this case `c' will be a continuation that expects
> another continuation, which will in turn be passed `42'.  So:
>
>    (throw (call-with-current-continuation (lambda (c) (throw c k))) 42)
>
> is the same as:
>
>    (throw k 42)

Ok.  I didn't give the example I thought I had.

In Scheme now (without discarding continuations) all continuations are part
of a tree rooted at some null continuation established when Scheme booted.
I was concerned that if throw disconnects its continuation before receiving
the new one, that you'd be able to detach part of the tree.  But on further
thought, I can see how you could do this safely.  Rather than have throw
discard its continuation via some magic side effect, it can discard its
continuation
by invoking a continuation captured near the root.  So you can do this
in `regular' scheme.