[plt-scheme] trying to understand PLAI route-producer code...

From: keydana at gmx.de (keydana at gmx.de)
Date: Wed May 6 11:11:19 EDT 2009

Hi all,

I'm quite desperately trying to understand the route-producer code  
from PLAI (the mutating version) for some time now,  but somehow I  
don't get it ...

The code is:

(define route-producer
   (local ((define resume (box false)))
     (lambda (real-send)
       (local ((define send-to (box real-send))
               (define send (lambda (value-to-send)
                      (set-box! send-to
                                (let/cc k
                                    (set-box! resume k)
                                    ((unbox send-to) value-to- 
         (if (unbox resume)
             ((unbox resume) real-send)
               (send 'providence)
               (send 'houston)
               (send 'bangalore)))))))

(call/cc route-producer)

My main problem is the

(set-box! send-to
                                (let/cc k
                                    (set-box! resume k)
                                    ((unbox send-to) value-to- 

part. I don't understand how I can ever get any value out from a  
single call. The first time, (send 'providence) will be executed, but  
it would seem to me that this - besides storing the continuation in  
resume - just sets the box value to the result to the application of  
'providence to the first boxed continuation. Or now I think - perhaps  
nothing is stored in the box, because the continuation returns  
immediately, without ever executing this mutation? But here I'm on the  
wrong track too I think, because then the box value would never get  

I've also looked for an "easier" way to simulate this, but did not get  
it working. I've tried something like (doesn't work)

(define thebox (box (call/cc (lambda (k) (lambda (value) (k value))))))
(set-box! thebox
           (let/cc k
               (display "beginning")
               ((unbox thebox) 'value-to-send))))

Here already, it's not clear to me to which original value to set the  
box to simulate the producer example.

Perhaps someone has time for a littel hint what to do to understand  
the code...

Thanks a lot in advance

Posted on the users mailing list.