I have been reading about call-with-current-continuation
particularly in Scheme and have read various articles on many websites. However, I still don't understand how does the control flow work while using call-with-current-continuation
.
For example, given the below attached code, how is the continuation invoked and whenever it is invoked, how does the control flow through the body of this procedure?
(define call/cc call-with-current-continuation)
(define showit (lambda (a b)
(begin (display a) (display b) (display " "))))
(define f
(lambda (n)
(let ((p (call/cc (lambda (k) k))))
(begin
(showit ’f= n)
p))))
Also, when this procedure is run using ((f 2) (f 4))
it results in infinite loop with the pattern like this:
Can anyone explain the reason behind the infinite loop? Note: Using Drracket with R5RS