[racket] internal define

From: J. Ian Johnson (ianj at ccs.neu.edu)
Date: Fri Nov 30 12:12:11 EST 2012

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.
----- 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


I have been forcing myself to use (define) over (let),
following the guide:

So I have come across this strange behavior:

(define (test x)
     (display x)
     (define x 2)
     (display x))
 > (test 1)

while the analogous construct with (let) works as expected:

(define (test1 x)
     (display x)
     (let ((x 2))
       (display x)))
 > (test1 1)

Is there a list of what one can do and what one can not
do with internal define?

Best regards,

  Racket Users list:

Posted on the users mailing list.