Re: De-facto standard CL implementation of continuations?
- From: Tim Wilson <no.email@xxxxxxxxxx>
- Date: Sun, 14 Aug 2005 06:35:25 GMT
On Sat, 13 Aug 2005 23:20:49 +0000, Ray Dillinger wrote:
> It's not required by the standard, but in many of the
> better scheme implementations, you can use read and
> write to serialize/deserialize continuations, both
> to/from files and strings.
>
> I haven't looked at exactly how it works though
Neither have I, but that won't stop me from speculating ;-)
> now that I think about it I'm curious how they avoid garbage
> collecting the invocation frames of the procedure calls
> involved if they don't maintain a reference to the
> continuation.
This, I believe, is orthogonal to serialization.
> Or maybe they have to serialize the
> entire "stack" with a continuation read it back in,
> and replace any collected frames. But then mutations
> in scoped variables don't get preserved if the frame
> is mutated and then reaped before the continuation is
> read back, so how.... ?
There are a few issues going on here. I'm guessing here, but I would say
that compilers that do serialize are just giving you something for free.
When handling your normal everyday continuations there are generally two
methods: i) copy stack on capture, ii) allocate *all* frames in heap
avoiding the stack entirely. When you already have written the code to
copy the stack, it's trivial to write it out to a file. And there is no GC
issue as the stack is self-contained (i.e. all local variables are
contained in the stack and references are stack offsets). Think of it as
writing a C struct to a file and reading it back in (modulo alignment
issues). The fields contain the correct data, so far as correct means what
you serialized. If you mutate a field, exit the program, load the
program and read the serialized struct... you only get the version of the
field (variable) you saved.
All that said, you might run into a problem if you do something like...
(set! *global-var* (call/cc (lambda (k) (save-cont-to-file k)))
Then later reload the system but forget to load the right modules or
define all the top-level variables. Nasal demons, etc. etc.
The stack method is seen as the more difficult method to implement, so
it would be no surprise if the better implementations used it. And while
we're at it... the theory goes, those that use call/cc should pay the
higher price (stack copy method) rather than penalize all procedure calls
(heap). But the "heap is slow" theory has been disputed, and it all
really depends on so many more details that, if you didn't know your
requirements, you could flip a coin and it wouldn't make a bit of
difference which method to pick.
Tim
.
- References:
- De-facto standard CL implementation of continuations?
- From: Andreas Thiele
- Re: De-facto standard CL implementation of continuations?
- From: Eric Lavigne
- Re: De-facto standard CL implementation of continuations?
- From: Eric Lavigne
- Re: De-facto standard CL implementation of continuations?
- From: Andreas Thiele
- Re: De-facto standard CL implementation of continuations?
- From: Marco Baringer
- Re: De-facto standard CL implementation of continuations?
- From: Jamie Border
- Re: De-facto standard CL implementation of continuations?
- From: Ray Dillinger
- De-facto standard CL implementation of continuations?
- Prev by Date: Re: ILC2005: McCarthy denounces Common Lisp, "Lisp", XML, and Rahul
- Next by Date: Statistics for comp.lang.lisp
- Previous by thread: Re: De-facto standard CL implementation of continuations?
- Next by thread: Re: De-facto standard CL implementation of continuations?
- Index(es):
Relevant Pages
|
|