[plt-scheme] Question about fluid-let

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Fri Dec 30 14:30:13 EST 2005

A better name for fluid-let is "temporary assignment with sensitivity 
about continuation entries and exits". -- Matthias


On Dec 30, 2005, at 1:02 PM, Greg Woodhouse wrote:

> Okay. I'm not sure I understand the explanation of fluid-let. I defined
> bump-counter this way
>
> (define bump-counter
>   (lambda ()
>      (set! counter (+ counter 1))
>      counter))
>
> and then did the following
>
>> (define counter 100)
>> counter
> 100
>> (define counter 1)
>> (fluid-let ((counter 99))
>     (display (bump-counter)) (newline)
>     (display (bump-counter)) (newline)
>     (display (bump-counter)) (newline))
> 100
> 101
> 102
>> counter
> 1
>> (let ((counter 99))
>     (display (bump-counter)) (newline)
>     (display (bump-counter)) (newline)
>     (display (bump-counter)) (newline))
> 2
> 3
> 4
>>
>
> This is not what I expected. My only thought that the scope of counter
> in the definition of bump-counter is unrelated to the scope introeuced
> by let in the second example, so bump-counter affects the binding in
> effect when it was defined, not when it is used. Is this what is
> referred to as a closure?
>
> Anyway, I wonder if fluid-let doesn't actually introdeuce what I'd call
> a dynamic scope in Perl, Python or MUMPS (meaning the binding is
> accessed via a dynamic link), or am I on the wrong track?
>
> ===
> Gregory Woodhouse  <gregory.woodhouse at sbcglobal.net>
> "Interaction is the mind-body problem of computing."
> --Philip L. Wadler
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme



Posted on the users mailing list.