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

From: John Clements (clements at brinckerhoff.org)
Date: Wed Jun 15 09:30:39 EDT 2005

On Jun 14, 2005, at 12:21 PM, Jay McCarthy wrote:

> I agree my example code as very simple, but it was to demonstrate the
> form of meaningful code.
>
> The actual code is for the following purpose:
>
> A web servlet would like to have a sortable list on a page. To
> generate the code to do this, that code must provide (a) procedures to
> sort the list for $n$ styles of sorting and (b) make sure that the
> code that uses these procedures is recalled after each sort so the
> page gets displayed.
>
> (b) is accommodated with the current-continuation at the time of the
> calling of the code generation.
>
> (a) is accommodated by generating code that resorts the list,
> returning the result to the current-continuation.
>
> The problem comes from wanting to allow sorts to 'stack' or to be
> reversed after a double click. If a set! is used then the Orbitz bug
> appears and the current sort order becomes global, rather than just
> for the future of the computation. The way around the Orbitz bug is to
> use fluid-let, but this doesn't work when the code (a) calls a
> continuation.
>
> Hopefully this justification shows how the example code was the 'gut'
> of what I was trying to do: get something like fluid-let to work
> around continuation calls.
>
> Jay

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.

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 ...)))

Am I missing something here?

John
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2430 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20050615/12f779b7/attachment.p7s>

Posted on the users mailing list.