I have this coroutine example
(define p1
(lambda (continuation)
(display "1")
(newline)
(p1 (call/cc continuation))))
(define p2
(lambda (continuation)
(display "2")
(newline)
(p2 (call/cc continuation))))
(p1 p2)
And I would like to change it in CPS so that I can use the CPS call/cc :
(define (call/cc-cps f continuation)
(define (exit value actual-continuation)
(continuation value))
(f exit continuation))
I know that to transform a function in CPS I need to add a continuation to the fonction but I'm quite confused and I don't really know how to do it.
I think that it would look like that :
(define p1
(lambda (continuation)
(display "2")
(newline)
(call/cc-cps
(lambda (continuation actual-continuation)
continuation) ;; or actual-continuation ?
(lambda (value)
(p1 value)))))
(p1 p2)
But It's probably wrong. Can someone help me understand how to do it correctly ?
Thank you