[racket] Why is x can be simultenaously bind and not bind ?

From: Andre Mayers (Andre.Mayers at USherbrooke.ca)
Date: Sun Sep 15 20:08:08 EDT 2013

Thank you, it is very helpful. 

-----Message d'origine-----
De : Jon Zeppieri [mailto:zeppieri at gmail.com] 
Envoyé : 15 septembre 2013 19:21
À : Andre Mayers
Cc : users at lists.racket-lang.org
Objet : Re: [racket] Why is x can be simultenaously bind and not bind ?

It may be helpful to look at the full expansion of your program. If you open
a fresh Dr. Racket buffer and enter the following program:

#lang racket/base

(let ([x 'uuu])
  (define x 'a)

Then, press the "Macro Stepper" button and, in the macro stepper dialog,
disable macro hiding (using the dropdown menu at the bottom), and then press
the "End" button, you'll see the following expansion:

(module anonymous-module racket/base
  (#%module-begin (#%app call-with-values (lambda () (let-values (((x)
'uuu)) (let-values (((x) 'a)) x))) print-values)))

The expansion makes explicit the nesting of lexical scopes.


On Sun, Sep 15, 2013 at 6:44 PM, Jon Zeppieri <zeppieri at gmail.com> wrote:
> On Sun, Sep 15, 2013 at 6:34 PM, Andre Mayers 
> <Andre.Mayers at usherbrooke.ca> wrote:
>> Thank you for your answer. But it is still not clear.
>>> (let ([x 'uuu])
>>>   (define x 'a)
>>>   x)
>> This:
>> 1. creates a binding [x => 'uuu]
>> 2. creates a different binding [x => 'a] that shadows the existing 
>> binding of x 3. gives the value of the *visible* binding of x, namely 
>> 'a
>> The two binding [x => 'uuu] and [x =>'a] are exactly in the same 
>> lexical space (the second binding is not in a lexical subspace) and 
>> that doesn't make sense for me.
> No, they're not. As the reference says:
>      Definitions in an internal-definition context are equivalent
>      to local binding via letrec-syntaxes+values...[1]
>> As far as I know, to shadow a binding, you have to create a lexical 
>> subspace. Am I wrong ?
> You're not wrong about that, but an internal definition expands into a
> letrec-syntaxes+values form, which does in fact create a new lexical
> scope.
> -Jon
> [1] 
> http://docs.racket-lang.org/reference/syntax-model.html?q=internal#%28
> part._intdef-body%29

Posted on the users mailing list.