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

From: Veer (diggerrrrr at gmail.com)
Date: Sun Jul 10 03:31:45 EDT 2011

Thanks for taking time out to explain.
Now I got it that define introduces identifier binding before
it evaluate it expression part, so that we can refer
to it in the expression.

Thanks again.

On Sun, Jul 10, 2011 at 12:19 PM, Eli Barzilay <eli at barzilay.org> wrote:
> A few seconds ago, Veer wrote:
>> I don't get it , can you explain in terms of environment and
>> interpretation .
>
> `define' is defining a potentially recursive value, so that
>
>  (define (loop) (loop))
>
> works as you expect.  In simple terms, you can think about an internal
> define as something that expands to a `letrec'.  So what you wrote is
> basically the same as
>
>  (define (make-color color)
>    (letrec ([color color])
>      ...))
>
> The scope of a `let' binding covers the body expression(s), and the
> scope of a `letrec' binding covers the initial expression too.
>
>
>> The simplistic view that I have is : The body of a function executes
>> , it encounters define form so expression part of define is
>> evaluated and bound to identifier part of define in a environment ,
>> it then encounters the identifier color and then value of color is
>> returned.
>
> That would be a `let' behavior, which internal `define's don't use in
> racket.  (Or in any scheme.)
>
> --
>          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
>                    http://barzilay.org/                   Maze is Life!
>



Posted on the users mailing list.