I'm new to Racket and I'm trying to use call/cc. When I put the following code in the definitions window
of DrRacket, run it, and type (saved-k 0) in the interactions window, I get two of 3 printed.
#lang racket ; the definitions window
(define saved-k #f)
(define (f)
(+ 1
(call/cc (λ (k) (set! saved-k k) 0))))
(+ 1 (+ 1 (f)))
; the interactions window
3
> (saved-k 0)
3
3
My understanding is that the saved continuation should be (+ 1 (+ 1 (+ 1 ?)))
where ? is the hole. Why are there two results printed?
When I try all of those things in the interactions window, everything looks normal.
; the interactions window
> (define saved-k #f)
> (define (f)
(+ 1
(call/cc (λ (k) (set! saved-k k) 0))))
> (+ 1 (+ 1 (f)))
3
> (saved-k 0)
3