Hi all,<br><br>Say I have the following:<br><br>(define r #f)<br>(define count-calls 0)<br><br>(begin<br> (call/cc<br> (lambda (k)<br> (set! r k)<br> #t))<br> (set! count-calls (+ count-calls 1)))<br>(r #t) (r #t) (r #t)<br>
<br>I would expect count-calls to equal 4 after this, but it equals 1. The continuation, from what little I've read about this, should look like:<br><br>([#procedure] [#hole] (set! count-calls (+ count-calls 1)))<br><br>
where 'begin' has been evaluated, but the (set!) expression has not. Surely picking up again from #hole should call (set!) each time? I could understand this behaviour if I'd instead written:<br><br>(begin<br>
(set! count-calls (+ count-calls 1))<br>
(call/cc<br>
(lambda (k)<br>
(set! r k)<br>
#t)))<br>
(r #t) (r #t) (r #t)<br><br>Then the continuation would be:<br><br>([#procedure] [#undefined] [#hole])<br clear="all"><br>Could someone explain what's going on, and tell me whether there are other exceptions I'd be surprised by? I thought maybe it was saving the state of all variables with the continuation, but this would seem to refute that:<br>
<br>(set! count-calls 0)<br>(define (foo)<br> (call/cc<br> (lambda (k)<br> (set! r k)<br> #t))<br> (set! count-calls (+ count-calls 1)))<br>(foo)<br>(r #t) (r #t) (r #t)<br><br>; count-calls = 4<br><br>-- <br>
James Coglan<br>