<div dir="ltr"><div>Hello!</div><div><br></div><div>I've been writing some tricky code involving continuations, and ran into the</div><div>following surprising behavior from Gambit v.4.6.2 running on OSX. </div><div><br>
</div><div>I have two versions of "make-jp", that I believe should be</div><div>equivalent. </div><div><br></div><div>   Version 1:</div><div>      (define (make-jp block)</div><div>        (let [(return-point '())]    </div>
<div>          (call/cc (lambda (ret)</div><div>            (define (jp x)</div><div>              (call/cc (lambda (ret)</div><div>                 (let [(r return-point)]</div><div>                   (set! return-point ret)</div>
<div>                   (r x)))))</div><div>            (set! return-point ret)</div><div>            (let [(result (block jp))]</div><div>              (return-point result))))))</div><div><br></div><div>   Version 2: </div>
<div>      (define (make-jp block)</div><div>        (let [(return-point '())]    </div><div>          (call/cc (lambda (ret)</div><div>            (define (jp x)</div><div>              (call/cc (lambda (ret)</div><div>
                 (let [(r return-point)]</div><div>                   (set! return-point ret)</div><div>                   (r x)))))</div><div>            (set! return-point ret)</div><div>            (return-point (block jp))))))</div>
<div><br></div><div>The only difference is the final line:</div><div><br></div><div>   Version 1:</div><div>      (let [(result (block jp))]</div><div>        (return-point result))</div><div><br></div><div>   Version 2:</div>
<div>      (return-point (block jp))</div><div><br></div><div><br></div><div>However, I get different behavior when I test with the following code:</div><div><br></div><div>   Testing Code:</div><div>      (let* [(j '())]</div>
<div>        (make-jp (lambda (y)</div><div>           (set! j y)</div><div>           (y 0)</div><div>           10))</div><div>        (println "GOT: " (j "X")))</div><div><br></div><div>   Version 1 prints:</div>
<div>      GOT: 10</div><div><br></div><div>   Version 2 prints:</div><div>      GOT: X</div><div><br></div><div>Out of the two behaviours, I expect the answer given by Version 1. </div><div><br></div><div>Can anyone verify whether this is a bug, and whether the latest</div>
<div>version also shows this behavior?  This fell out of a piece of code</div><div>I'm using to simulate coroutines for an interpreter that I am</div><div>programming. Here I've tried to isolate the problem down to as few</div>
<div>lines as possible.</div><div><br></div><div>Once I get my environment fixed, I will try it on the latest version</div><div>of Gambit as well and see if the problem is still there.</div><div><br></div><div>  -Patrick</div>
<div><br></div></div>