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

From: John Clements (clements at brinckerhoff.org)
Date: Tue Jun 14 10:18:00 EDT 2005

On Jun 14, 2005, at 9:31 AM, Jay McCarthy wrote:

>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
> I have code similar to this:
>
> (define foo 1)
> (define (bar/set x)
>   (let/cc k
>     (set! foo x)
>     (k foo)))
> (define (bar/fluid-let x)
>   (let/cc k
>     (fluid-let ([foo x])
>       (k foo))))
>
> (define (zog)
>   (begin
>     (display foo)
>     (display (bar/set 2))
>     (display foo)
>     (display (bar/fluid-let 3))
>     (display foo)))
>
> (zog) ; => 12232

Jay, at the risk of looking like an idiot myself (slowly becoming 
accustomed to this), it looks to me as though your uses of 
continuations are all trivial[*], and therefore that your code is 
equivalent to

(define foo 1)
(define (bar/set x)
   (set! foo x)
   foo)

(define (bar/fluid-let x)
   (fluid-let ([foo x])
     foo))

(define (zog)
   (begin
     (display foo)
     (display (bar/set 2))
     (display foo)
     (display (bar/fluid-let 3))
     (display foo)))

(zog) ; => 12232

... that is, I took out all the let/cc's and their invocations.  So 
now, we can always replace (fluid-let ([foo x]) foo) with a simple 
'x'... if you're not using a reference to the original binding that was 
captured outside the fluid-let, you're not going to see any difference 
between a 'fluid-let' and a 'let'.

Well, that's my quota of single-quotes for the day.

John



[*]

I claim that

(let/cc k M0 .... (k N))

is equivalent to

(begin M0 ... N)

if there are no references to k in any of M0 ... or N.


> So, a fluid-let cannot do its business in the face of continuations.
> And the (zog) shows that this is not top-level weirdness.
>
> I am willing to accept that this is illegal. I'm just curious why.
>
> Jay
>
> -- 
> Jay McCarthy <jay at cs.brown.edu>
> http://jay.makeoutcity.com/
>
-------------- 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/20050614/7d91f601/attachment.p7s>

Posted on the users mailing list.