[gambit-list] Dynamic bindings?

Marc Feeley feeley at iro.umontreal.ca
Tue Mar 4 18:55:11 EST 2008


On 4-Mar-08, at 6:05 PM, David St-Hilaire wrote:

> Ok Thx! But having x defined as a global variable, and thus being  
> present in the lexical scoping of f when it is defined doesn't feel  
> much like dynamic bindincs, doesn't it? If we do something like:
>
> > (define x (make-parameter #f))
> >
> > (define (f) (pp (x)))
> >
> > (set! x 'oups)
> > (parameterize ((x 10))
> >   (f))
>
> results in an error, but doesn't dynamic scoping would permit  
> something like that?

A parameter object is not a variable, it is an object...  You can bind  
it to a variable (global or not), but that's just a way to give it a  
"name" so that you can refer to it in the rest of your code.  So when  
you do

(define x (make-parameter #f))

all code that can see the variable x has access to the parameter  
object.  You could use a local variable as in

(let ()

    (define x (make-parameter #f))

    ...)

and then only the body of the let has access to the parameter object.   
This is not a bug... it's a feature (because you have more control  
than a globally visible "dynamically scoped variable").

The "dynamic binding" aspect is obtained with the (parameterize ...)  
form, which is the analog of your (dynamic-let ...).

This is a bit amusing because in earlier versions of Gambit, "dynamic- 
let" was supported with the semantics you seem to expect.

Marc




More information about the Gambit-list mailing list