I am learning continuations but I can't wrap my head around this code. Why does it go into infinite loop?
(let ((cont #f))
(call/cc (lambda (k)
(set! cont k)))
(cont #f))
I am learning continuations but I can't wrap my head around this code. Why does it go into infinite loop?
(let ((cont #f))
(call/cc (lambda (k)
(set! cont k)))
(cont #f))
Line by line:
contcall/cc (and here is eventually ignored).k here signifies everything, that will happen after, in our case something close in sense to (lambda (call/cc-retval) (let () call/cc-retval (cont #f))). We set cont value to this continuation. call/cc returns.cont is now a function which represented the continuation, and it's argument is the "return value of call/cc", we just call that function, the argument gets ignored, and we need to call the (cont #f) again.Thus, what we get eventually is infinite loop.