I came across something that I can not understand.
#lang scheme
(define cc #f)
(define (val!)
(call/cc
(lambda (k)
(set! cc k)
0)))
(* 10 (val!))
(cc 100)
So far so good; the continuation of (* 10 [])
is stored in cc
and if we call (cc 100)
we see 1000
in the REPL as expected.
But the next thing I tried was to define a variable to be the result of running the continuation:
(define x (cc 20))
I see 200
as a result in the REPL, but x
does not get defined.
Does the continuation stored in cc
include its returning so that the call to define
never returns and instead the evaluation is the result of (* 10 val)
? What is going on?