I often ponder what
send/suspend really is. It is a lot like
call/cc, but has the curious property that the continuation escapes in a single way and is only called in a particular context. I often wonder if there is something weaker than
call/cc that implements
Today I wrote a little dispatcher that uses threads to implement
send/suspend. In this implementation, sending truly suspends the computation.
Here's the code: http://www.copypastecode.com/codes/view/5003
The trick is to have channels for communicating responses and requests. When you run this example, you should be able to add two numbers. But, in contrast to the normal
send/suspend, all the URLs are one-shots, because once the computation is resumed, it moves forward... it is never saved.
This implementation technique also precludes clever implementations of
(define (send/suspend/dispatch mk-page) (let/cc k0 (send/back (mk-page (lambda (handler) (let/ec k1 (k0 (handler (send/suspend k1)))))))))