[racket] why do I get undefined , when using internal definition?

From: Eli Barzilay (eli at barzilay.org)
Date: Sun Jul 10 03:02:39 EDT 2011

15 minutes ago, Neil Van Dyke wrote:
> Eli Barzilay wrote at 07/10/2011 02:25 AM:
> >> it should work as you originally expected, or it should raise an
> >> error to complain about an internal "define" referencing itself like
> >> that and ignoring the pre-existing binding from the argument.
> >>     
> >
> > An error would be nice, but racket never did that.  Same as `letrec'.
> So, I think that this should be an error, given the current
> semantics:
> (define X X)
> Maybe that's an extremely simple example of a more general error of
> attempting to evaluate an uninitialized variable.  At least, I think
> that the ones that can be proven statically to always be
> uninitialized references should be compile errors.  Or is there a
> good reason for the compiler to be more liberal?

I don't remember if there's a good reason for that.  (And I'm sure
that others will have plenty to say about it in the morning.)  I also
don't remember any implementation that does such a check, though some
will throw a runtime error.

> Separately, I also think that maybe the following should be an error, 
> since someone doing this with internal-"define" instead of "let" is most 
> likely a student, and a student probably doesn't mean to do this:
> (define (foo name)
>   (define name ...)
>   ...)

Yes, like I said -- such an error would be nice, if possible.  (Not
only for students -- every once in a while I'll move some `let'
bindings into internal defines for convenience, and this is an easy
trap to fall into.)

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!

Posted on the users mailing list.