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

From: Carl Eastlund (carl.eastlund at gmail.com)
Date: Wed Jun 24 14:19:04 EDT 2009

To clarify Matthias's statement, bar is bound in foo2, just not
evaluated.  This is a run-time error rather than a compile-time one.

On Wed, Jun 24, 2009 at 2:13 PM, Matthias Felleisen<matthias at ccs.neu.edu> 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.
>
> 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


Posted on the users mailing list.