[r6rs-discuss] What is a reference? (was Remaining inconsistencies...)

From: AndrevanTonder <andre>
Date: Sun, 8 Jul 2007 16:20:03 -0400 (EDT)

On Sat, 7 Jul 2007, AndrevanTonder wrote:

> I am wondering if my interpretation of the r6rs draft is correct in
> the following cases...

I think my confusion comes down to the meaning of "referenced" in

    A level is a lexical property of an identifier that determines in which
    phases it can be referenced.

Without a definition of "referenced", it is really impossible to know if some
reasonable code is valid r6rs. For example, this might not be portable

   (import (rnrs base))
   (define-syntax list-macro
     (syntax-rules ()
       ((_ x ...) (list x ...))))

since even though LIST is imported for RUN only, its binding has to be looked
up at EXPAND time, while processing the template, to check if it is in fact a
(renamed) reference to the ... literal. So we are in trouble unless this
lookup of LIST does not count as being referenced.

But the lookup of ... in the template apparently counts as being
referenced at expand time (since r6rs requires us to import ... for expand).
Therefore, if the comparison of LIST with ... were to show that they were the
same binding, then this lookup of LIST, like that of ..., would also count as
an expand-time reference.

This line of reasoning leads us to:

   Whether a binding lookup of an identifier counts
   as a reference in a given phase may depend
   on whether it is free-identifier=? to some other binding. Commonly,
   the other binding would be some macro literal (such as ...).

In other words, given the definition

    (library (foo)
      (export test)
      (import (r6rs base))
      (define-syntax test
        (syntax-rules (car)
          ((_ car) #t)
          ((_ k) #f))))

then, in analogy with the list-macro example above (the case where LIST
denoted the same binding as ...), the use of CAR in the following should count
as a reference and is therefore at an invalid level:

    (library (bar)
      (export)
      (import (for (r6rs base) (meta 21))
              (foo))
      (test car))

          ==> Attempt to use binding car in library (bar) at invalid level 0.
              Binding is only available at meta levels: 21

BUT, still in analogy with the list-macro example, the following should be
correct and portable r6rs, since the level 21 CDR is not free-identifier=?
to the literal CAR in FOO and therefore does not count as a reference
(just like when the level 0 LIST was different from ..., it did not
count as a reference at expand-time):

    (library (bar)
      (export)
      (import (for (r6rs base) (meta 21))
              (foo))
      (test cdr))

The problem is that I don't know how an implementation could detect if an
identifier is actually a literal (in general).

Also, consider inverting the first example above: Does the following count
as a reference, and is this program portable r6rs?

    (library (foo)
      (export test)
      (import (except (r6rs base) car)
              (for (only (r6rs base) car) (meta 21)))
      (define-syntax test
        (syntax-rules (car)
          ((_ car) #t) ;; is this a reference?
          ((_ k) #f))))

    (library (bar)
      (export)
      (import (r6rs base))
              (foo))
      (test car))

As in the first example, we are comparing a level 0 and a level 21 instance
of CAR. I am not sure if this should be portably valid or not.

Just to add to the list of horrors, is this portable r6rs or not?

    (library (foo)
      (export test)
      (import (except (r6rs) car)
              (for (only (r6rs) car) (meta 21)))
      (define-syntax test
        (lambda (form)
          (free-identifier=? (syntax car) (syntax car)))))

    (import (foo))
    (test)

Cheers
Andre
Received on Sun Jul 08 2007 - 16:20:03 UTC

This archive was generated by hypermail 2.3.0 : Wed Oct 23 2024 - 09:15:01 UTC