[plt-dev] What is send/suspend?

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Tue May 5 17:19:33 EDT 2009

I thought some of you may be intrigued by this.

[From http://jay-mccarthy.blogspot.com/2009/05/what-is-sendsuspend.html ]

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 send/suspend.

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
send/suspend/dispatch, like:

(define (send/suspend/dispatch mk-page)
  (let/cc k0
    (send/back
     (mk-page
      (lambda (handler)
        (let/ec k1
          (k0 (handler (send/suspend k1)))))))))

Jay

-- 
Jay McCarthy <jay at cs.byu.edu>
Assistant Professor / Brigham Young University
http://teammccarthy.org/jay

"The glory of God is Intelligence" - D&C 93


Posted on the dev mailing list.