I am looking at the following example for a coroutine from http://community.schemewiki.org/?call-with-current-continuation:
(define (hefty-computation do-other-stuff)
(let loop ((n 5))
(display "Hefty computation: ")
(display n)
(newline)
(set! do-other-stuff (call/cc do-other-stuff)) ; point A
(display "Hefty computation (b)")
(newline)
(set! do-other-stuff (call/cc do-other-stuff))
(display "Hefty computation (c)")
(newline)
(set! do-other-stuff (call/cc do-other-stuff))
(if (> n 0)
(loop (- n 1)))))
superfluous work:
;; notionally displays a clock
(define (superfluous-computation do-other-stuff)
(let loop ()
(for-each (lambda (graphic)
(display graphic)
(newline)
(set! do-other-stuff (call/cc do-other-stuff)))
'("Straight up." "Quarter after." "Half past." "Quarter til.")) ; point B
(loop)))
(hefty-computation superfluous-computation)
For the first usage of call/cc, what is the context supposed to be? When I say context, I mean where are we supposed to "return to" as a result of callcc's jump?
From what I understand, the first time you call call/cc, do-other-stuff essentially becomes a procedure that executes the code of superfluous-computation and then jumps to the point right after the set! (point A). The second time, it will wrap its "jump to point B" behavior around the "jump to point A and execute the context, or whatever code follows point A". Is this correct?
It doesn't seem like this code would work if the set! actually happened. Or is the set! necessary for this code to work?
A visual representation of what's going on would really help.