[racket] What is `Apparent Identifier Binding`?

From: Ryan Culpepper (ryanc at ccs.neu.edu)
Date: Thu Jan 15 17:37:29 EST 2015

"Apparent identifier binding" just shows the result of the 
identifier-binding function. It is labeled "apparent" because macro 
expansion is a discovery process, and if the identifier is in an 
unexpanded part of the program, the macro expander might discover 
additional binding forms that change its meaning before getting to the 
identifier itself.

The binding an identifier refers to depends on the marks, but it also 
depends on the environment where the identifier first occurred.

Here's one example:

   (define-syntax-rule (m)
     x)

   (define-syntax (m2 stx)
     (syntax-case stx ()
       [(m2)
        (syntax-local-introduce #'x)]))

   (lambda (x)
     (m)
     (m2)
     x)

In the lambda body, the x's produced by m and m2 both have apparent 
identifier binding of "none", but the direct use of x has binding 
"lexical". The x produced by m has a mark from the expansion of m, but 
the one produced by m2 has no mark, because m2 cancels it out using 
syntax-local-introduce.

Here's another example:

   (define-syntax (m3 stx)
     (syntax-case stx ()
       [(m3)
        (with-syntax ([x1 #'x]
                      [x2 (let ([x 'whatever]) #'x)])
          #'(void x1 x2))]))

   (m3)

The first x produced by m3 has a binding of "none", but the second one 
has a binding of "lexical" due to the let binding *in the implementation 
of the macro*. If the expander gets to the second x reference, it will 
raise an "identifier used out of context" error; that error is usually 
caused by a macro like the one above using the same name as an 
implementation-level binding and in the generated syntax.

Ryan


On 01/15/2015 01:28 PM, Spencer Florence wrote:
> Hey All,
>
> I'm trying to understand why two identifiers I have don't reference the
> same value. If I look at them in the macro stepper all of their
> properties and marks are the same, with the exception of "Apparent
> identifier binding". One has "lexical (all phases)" and the other
> "none". What is "Apparent identifier binding" and how does it get
> determined?
>
> --spencer
>
>
> ____________________
>    Racket Users list:
>    http://lists.racket-lang.org/users
>


Posted on the users mailing list.