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

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

I don't get it , can you explain in terms of environment and interpretation .

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.

Sorry if I am using wrong terminology.

On Sun, Jul 10, 2011 at 11:28 AM, Eli Barzilay <eli at barzilay.org> wrote:
> 10 minutes ago, Veer wrote:
>> Following code returns #<undefined> :
>> (define (make-color color)
>>  (define color color)
>>  color)
>> (make-color 'red)  ;; => #<undefined>
>> From the guide , I get that internal definition of color is not initialized
>> therefore the result is #<undefined> . What does not initialized means
>> in this context.
> You're defining a new `color', one that shadows the `color' input.  If
> you click check-syntax and hover over the different `color's you'll
> see helpful arrows that indicate the bindings.  (For the argument
> you'll see *no* errors.)  `define' is basically defining a new
> identifier -- it's different from `set!', and sometimes confused since
> in many languages `=' is used for both.
>> My assumption was that internal color will be bound to the value of
>> argument.
>> When was #<undefined> introduced (or it was always there).
> It was always there.  (Or at least since the time I started using
> MzScheme, which was around 1854.)
>> I "think" I have used this type of code before , and it worked fine
>> then.
> No, it always did that...
> --
>          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
>                    http://barzilay.org/                   Maze is Life!

Posted on the users mailing list.