Fw: [plt-scheme] identifier binding to undefined identifier

From: Jos Koot (jos.koot at telefonica.net)
Date: Mon Nov 3 11:05:13 EST 2008

It appears that I did not cc my email on this topic to the PLT list.
Sorry. I am sure my answer is just the same as yours.
Jos

----- Original Message ----- 
From: "Jos Koot" <jos.koot at telefonica.net>
To: "Jon Rafkind" <workmin at ccs.neu.edu>
Sent: Monday, November 03, 2008 11:20 AM
Subject: Re: [plt-scheme] identifier binding to undefined identifier


>I answer because I did not see a reply from a more expert member of the 
>list. In case my answer is not fully acurate, I will certainly be 
>corrected.
>
> You won't have this problem within modules. It is a top level problem. In 
> a REPL for instance, the macro, i.e. syntax-transformer running at 
> expansion time, cannot know whether or not the identifier will be defined 
> later. At the top level every identifier that has no other binding is, 
> during expansion, supposed to be bound at top level. Without this, it 
> would not be possible to define a procedure in a REPL in terms of 
> procedures yet to be defined.
>
> REPL:
>
> (define (foo x) (bar (bar x)))
> ;During expansion identifier `bar' must be supposed to be bound later at 
> top level.
>
> (define (bar x) (+ x 1))
> ;And now `'bar' is bound indeed.
>
> (foo 3) ; --> 5
>
> In a module forward references are no problem, because a module is 
> expanded as a whole and can therefore see forward references.
>
> Jos
>
> ----- Original Message ----- 
> From: "Jon Rafkind" <workmin at ccs.neu.edu>
> To: "PLT-list" <plt-scheme at list.cs.brown.edu>
> Sent: Monday, November 03, 2008 12:40 AM
> Subject: [plt-scheme] identifier binding to undefined identifier
>
>
>> The docs say identifier-binding returns #f is the binding is a top-level 
>> binding but what if there is no binding at all?
>>
>> ;; (define y 2)
>>
>> (define-syntax (bar stx)
>>  (syntax-case stx ()
>>    ((_ id)
>>     (begin
>>       (printf "binding at ~a\n" (identifier-binding #'id))
>>       #'id))))
>>
>> (define-syntax foo
>>  (syntax-rules ()
>>    ((_) (let ((x 1))
>>           (bar y)))))
>>
>> (foo)
>>
>> This program prints "binding at #f" when (define y 2) is uncommented or 
>> not. What is the rationale for this? It seems more logical to return 
>> 'top-level if the identifier is bound at the top-level.
>> _________________________________________________
>>  For list-related administrative tasks:
>>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>>
> 



Posted on the users mailing list.