Hi all,<br><br>Say I have the following:<br><br>(define r #f)<br>(define count-calls 0)<br><br>(begin<br>&nbsp; (call/cc<br>&nbsp;&nbsp;&nbsp; (lambda (k)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (set! r k)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #t))<br>&nbsp; (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&#39;ve read about this, should look like:<br><br>([#procedure] [#hole] (set! count-calls (+ count-calls 1)))<br><br>
where &#39;begin&#39; 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&#39;d instead written:<br><br>(begin<br>
&nbsp; (set! count-calls (+ count-calls 1))<br>
&nbsp; (call/cc<br>
&nbsp;&nbsp;&nbsp; (lambda (k)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (set! r k)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #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&#39;s going on, and tell me whether there are other exceptions I&#39;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>&nbsp; (call/cc<br>&nbsp;&nbsp;&nbsp; (lambda (k)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (set! r k)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #t))<br>&nbsp; (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>