[plt-scheme] Undefined identifier? hey... it's defined!

From: Ryan Culpepper (ryanc at ccs.neu.edu)
Date: Wed Jun 24 17:09:19 EDT 2009

Paulo J. Matos wrote:
> On Wed, 2009-06-24 at 14:13 -0400, Matthias Felleisen wrote:
>> The rhs of definitions are evaluated in sequence. In foo2, you are  
>> evaluating (bar) in a context where foo1 is bound and evaluated and  
>> bar isn't. Nothing new.
>>
>> Then again, in a module this kind of thing could go away.
>>
>>
> 
> You're right.. it does make sense... wierd I only stumbled at it now. 
> I always thought that rhs of definitions were only evaluated in a
> sequence outside of a module and inside it wouldn't make sense.

What would you like this to produce?

   #lang scheme
   (define a (cons 1 b))
   (define b (cons 2 a))
   (write a)

(Perhaps the real lesson here is that procedure definitions are in no 
way special. They're just like other value definitions.)

Ryan



>> On Jun 24, 2009, at 2:02 PM, Paulo J. Matos wrote:
>>
>>> Hi all,
>>>
>>> When you think scheme hold no more strange surprises, you end up  
>>> finding
>>> something you can't explain. It's even worse when you understand the
>>> error message but you have no idea why it's being thrown at you.
>>>
>>> So this is just small example showing the problem:
>>> #lang scheme
>>>
>>> (define (foo1 x)
>>>   (let ([y (bar x)])
>>>     (+ y x)))
>>>
>>> (define foo2
>>>   (let ([y (bar)])
>>>     (lambda (x)
>>>       (+ y x))))
>>>
>>> (define (bar (x 2))
>>>   (* x x))
>>>
>>> I get in 4.2:
>>> reference to an identifier before its definition: bar
>>>
>>> Why is bar undefined in foo2?
>>>
>>> Cheers,
>>>
>>> Paulo Matos
>>>
>>> _________________________________________________
>>>   For list-related administrative tasks:
>>>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> 
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme



Posted on the users mailing list.