0
(+ 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.

user8314628
  • 1,952
  • 2
  • 22
  • 46

2 Answers2

1

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.

Will Ness
  • 70,110
  • 9
  • 98
  • 181
Óscar López
  • 232,561
  • 37
  • 312
  • 386
1

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.

John Clements
  • 16,895
  • 3
  • 37
  • 52