[racket] Saved continuations
I did this experiment with saved continuations in DrRacket
--------------------------------------------------
> (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 ()
(+ x (save-it) ))) ; continuation is (+ x []))
(saved-k 0)
(set! x 100)
(saved-k 0)
-------------------------------------
GIVES RESULTS
10
10
-------------------------------------------
(define x 10)
(call-with-continuation-prompt
(lambda()
(+ (save-it) x ))) ; continuation is (+ [] x))
(saved-k 0)
(set! x 100)
(saved-k 0)
---------------------------
GIVES RESULTS
10
100
Is this a querk of Dr. Racket or does this mean that if within a saved
continuation, a variable has not yet been reduced to a value at the
time the continuation was saved, that variable can be mutated changing
the behavior of the saved continuation?
Thanks,
Harry Spier