[racket] Saved continuations

From: D Herring (dherring at tentpost.com)
Date: Wed Sep 5 00:06:03 EDT 2012

On 09/04/2012 09:11 PM, Harry Spier wrote:
> Is it possible in Racket to make a kind of copy of a saved
> continuation with its environment at the time it was saved, so that no
> mutation of variables between the time the copy of the saved
> continuation was made and the time the copy is invoked can possible
> have any affect on the values the copy of the saved continuation
> produces?

Does an extra (let ...) do what you want, or do you want new bindings 
for *all* variables that are used in the continuation?

e.g.

#lang racket
(define saved-k #f)
(define (save-it) (call-with-composable-continuation
            (lambda (k)
            (set! saved-k k)
             0)))

(define x 10)
(call-with-continuation-prompt
  (lambda()
    (let ((x x)) (+ (save-it) x  ))))

(saved-k 0)
(set! x 100)
(saved-k 0)

- Daniel


Posted on the users mailing list.