[plt-scheme] Re: why no send/suspend in tutorial? (was: Re: web-server question)

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Mon Dec 8 23:54:49 EST 2008

Everything you can do with s/s you can do with s/s/d (and vice versa),
because send/suspend/dispatch returns the result of the request
handler to its continuation.

Send/suspend can be derived from s/s/d:

(define (send/suspend response-generator)
  (lambda (embed/url)
   (response-generator (embed/url (lambda (x) x))))))

In my implementation, s/s/d is derived from s/s:

(define (send/suspend/dispatch response-generator)
 (let/cc k1
   (lambda (proc)
    (let/ec k2
     (k1 (proc (send/suspend k2))))))))

As you can see, if proc = id, then s/s/d is just s/s.

I do agree that s/s/d encourages you to write your web app as set of
mutually recursive tail-calling functions, rather than linear
computation with send/suspend standing in for `read'. But, I think
that the s/s/d approach better matches most web apps, which is why I
used it in the tutorial.


On Mon, Dec 8, 2008 at 9:32 PM, John Clements <clements at brinckerhoff.org> wrote:
> On Dec 8, 2008, at 7:43 PM, Jay McCarthy wrote:
>> I think you are looking for send/suspend/dispatch:
>> (send/suspend/dispatch
>>  (lambda (embed/url)
>>  (let ([p ....])
>>   `(a ([href ,(embed/url (lambda (req) (remove-post! p) ....))]) ....)))
>> http://docs.plt-scheme.org/web-server/web_ss.html#(def._((lib._web-server/servlet/web..ss)._send/suspend/dispatch))
> I've been thinking about this for a few weeks now, but this prompts me (er,
> so to speak) to write:
> Send/suspend/dispatch seems like a sometimes-useful function, but that
> exclusive use of send/suspend/dispatch (as the new tutorial exemplifies)
> makes impossible the "nice" thing that continuations enable.  In particular,
> I'm thinking of code like this, from my solution to one of Shriram's
> assignments:
> (let loop ()
>  (let ([new-post (get-post)])
>    (when (confirm-post? new-post)
>        (add-post! new-post))
>    (loop))
> The idea is that get-post and confirm-post? both use send/suspend.  However,
> if you try to rewrite these to use send/suspend/dispatch, then you lose the
> ability to write the program this way without using hidden fields, which is
> really the raison d'etre of the PLT web server, IIUC.
> John Clements

Jay McCarthy <jay at cs.byu.edu>
Assistant Professor / Brigham Young University

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

Posted on the users mailing list.