I am trying this on Racket and it gives out the answer as 5. But I cannot seem to figure out how it got to the answer.
((call/cc call/cc) (lambda (x) 5))
I expanded it as follows.
((call/cc (lambda (k) (call/cc (lambda (k1) (k k1))))) (lambda (x) 5))
Assuming the expansion is correct I still don't understand what happens when k continuation is applied to k1 continuation and how it does to the execution of outer lambda to yield 5.
The
(k k1)
would returnk1
as the return value of the outercall/cc
. Then when you invokek1
(as part of(... (lambda (x) 5))
), that returns 5 as the return value of the innercall/cc
, which is then returned (as a normal return this time) as the return value of the outercall/cc
.Sorry, that was quite a mouthful. :-)