[racket] internal define

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Wed Dec 26 21:52:31 EST 2012

I added a warning to the style guide. 


On Nov 30, 2012, at 12:12 PM, J. Ian Johnson wrote:

> define does not have the same binding structure as let, much to my and many other people's lament.
> Within a tree of begin forms (and the implicit begin in a function body), there is a definition context that defines a new scope. Because you have a (define x 2) in this context, x starts bound to #<undefined> and once it is set by passing the define form, it is 2. This is the infamous behavior of letrec*.
> 
> Thus, the x passed to test was shadowed immediately entering the body and that is why your first reference is not as you expected. I would much rather a let-like binding structure for something similar to define, say define* or ilet (inline-let) or something.
> 
> You'll just have to use a different identifier for now.
> -Ian
> ----- Original Message -----
> From: "Dmitry Pavlov" <dpavlov at ipa.nw.ru>
> To: users at racket-lang.org
> Sent: Friday, November 30, 2012 12:03:12 PM GMT -05:00 US/Canada Eastern
> Subject: [racket] internal define
> 
> Hello,
> 
> I have been forcing myself to use (define) over (let),
> following the guide:
> http://www.ccs.neu.edu/home/matthias/Style/style/Choosing_the_Right_Construct.html#(part._.Definitions)
> 
> So I have come across this strange behavior:
> 
> (define (test x)
>     (display x)
>     (define x 2)
>     (display x))
>> (test 1)
> #<undefined>2
> 
> while the analogous construct with (let) works as expected:
> 
> (define (test1 x)
>     (display x)
>     (let ((x 2))
>       (display x)))
>> (test1 1)
> 12
> 
> Is there a list of what one can do and what one can not
> do with internal define?
> 
> Best regards,
> 
> Dmitry
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users



Posted on the users mailing list.