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

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

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.