Matt Might, in his posting on continuations by example, defines the helper function
(define (current-continuation)
(call/cc (lambda (cc) (cc cc))))
to grab and return the current continuation. Why use (cc cc) to return the continuation? Why not use cc:
(define (current-continuation)
(call/cc (lambda (cc) cc)))
Might's examples work identically with either version of current-continuation. Is this just a matter of style, or is there a deeper issue at work?
So, just to remember call/cc in CPS is this:
(define (call/cc& f k)
(f (lambda (v ignored-cont) (k v)) k))
So the first one does this:
(define (current-continuation k1)
(call/cc& (lambda (cc k2) (cc cc k2)) k1))
The second one does this:
(define (current-continuation k1)
(call/cc& (lambda (cc k2) (k2 cc)) k1))
Since call/cc will pass k1 as k2 and cc will use k1 both will end up doing (k1 cc). Thus there is no difference between the two.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With