[r6rs-discuss] [Formal] Violation of lexical scoping

AndrevanTonder andre at het.brown.edu
Mon Oct 23 13:52:57 EDT 2006


---
This message is a formal comment which was submitted to formal-comment at r6rs.org, following the requirements described at: http://www.r6rs.org/process.html
---
Name        : Andre van Tonder
Email       : andre at het.brown.edu
Type        : defect
Priority    : major
Component   : Expansion process
Version     : 5.91
Pages       : 27-28
Dependencies: Section 9.4 (Bodies and sequences)

Summary:
--------

The expansion process violates lexical scoping.

Description:
------------

According to r6rs, the expression

  (let ((x #f))
   (let-syntax ((foo (syntax-rules (x)
                       ((_ x y) (define y 'outer))
                       ((_ _ y) (define y 'inner)))))
     (let ()
       (foo x p)
       (define x #f)
       p)))

evaluates to "outer", whereas it would evaluate to "inner" if the definition 
preceded (foo x p).  This violates lexical scoping.

The following example, in addition to violating lexical scoping

  (let ((x #f))
    (let-syntax ((foo (syntax-rules (x)
                        ((_ x y) (define y 'outer))
                        ((_ _ y) 1))))
      (let ()
        (foo x p)
        (define x #f)
        p)))              ==> outer (wrong)

also violates the spirit (if not the letter) of the first paragraph on
p. 28: "It is a syntax violation if the keyword that identifies one
of the body forms as a definition (derived or core) is redefined
by the same definition or a later definition in the
same body."

However, this violation of the spirit will not be detected by the algorithm 
described in the same paragraph.

Suggestion:
-----------

The algorithm described in the first paragraph of p.28 may also have to
record the arguments of each use of free-identifier=?.  This is, however,
likely to be expensive.




More information about the r6rs-discuss mailing list