Reputation: 2042
(+ 2 (let/cc cont
(begin
(set! global-cont cont)
3)))
5
global-cont
#<continuation>
(global-cont 5) ; global-cont: (+ 2 _)
7
I know the whole block (+ 2 ... 3)))
is a continuation. But why global-cont
is a continuation also? I tried to check the let/cc
document, but it's hard to understand.
Upvotes: 0
Views: 67
Reputation: 235984
In this expression:
(let/cc cont body ...)
cont
is a continuation (+ 2 _)
, and in the body you're doing this:
(set! global-cont cont)
So basically you're assigning cont
to global-cont
, making it also a continuation.
Upvotes: 1
Reputation: 17203
I think I would disagree that "the whole block (+ 2 ...) is a continuation". If by "continuation" you mean "a value captured by let/cc or its equivalent (call/cc etc.)," then the whole block is not a continuation.
So: cont
is a continuation because you captured it with let/cc
. global-cont
is a continuation because you assigned a continuation to it.
Upvotes: 1