[plt-scheme] call/cc, set!, and fluid-let

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Wed Jun 15 09:47:32 EDT 2005

On 6/15/05, John Clements <clements at brinckerhoff.org> wrote:

> Taking this back to the list, hope that's okay.
> 
> After thinking about this for a bit, I see two things:
> 
> 1) I can just about imagine a situation like this where you want a
> change to be "permanent" for the rest of the computation but to be
> unwound when you hit the back button.

That's the ticket.

> 2) I don't understand why you need a thing like this for the situation
> you're describing.  I think I would just use a tail-call. Here's how I
> would structure the code, if I understand you correctly:
> 
> (define (sorting-proc-a l) ...)
> (define (sorting-proc-b l) ...)
> (define (sorting-proc-c l) ...)
> 
> (define (show-list l)
>    (send-suspend/callback-thingy (make-page l)
>       ; if user clicks "sort a":
>       => (show-list (sorting-proc-a l))
>       ; if user clicks "sort b":
>       => (show-list (sorting-proc-b l))
>       ; if user clicks "sort c":
>       => (show-list (sorting-proc-c l))
>       ; if user clicks something else:
>       => (call-to-somewhere-else ...)))

Add to this example that reclicking "sort a" goes in reverse, and that
clicking "sort a", "sort b" causes the list to be sorted by b with a
as the tie breaker. See how the code needs future-of-the-computation
state.

Furthermore, Sorting is just an example. For any given example you can
change make it work in a particular instance, if you are willing to
accept the pain. But if you want to have an embeddable component
library where the components may have future-of-the-computation state.

i.e.
(define (sortable-list-ui base-l sorts ...) ...)
(define (make-page l) 
 (send/suspend-thingy 
  (part-of-the-page 
   (sortable-list-ui l ...) 
   part-of-the-page)))

The sortable-list-ui must be able to case the rest of make-page to run
after each different sort, i.e. it must capture the continuation at
each call site.

I will be happy to be proved wrong and that there's a simple way to do
this. It will make the work much easier.

Jay

-- 
Jay McCarthy <jay at cs.brown.edu>
http://jay.makeoutcity.com/



Posted on the users mailing list.