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

From: AndrevanTonder <andre>
Date: Tue Oct 24 06:32:28 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.
Received on Mon Oct 23 2006 - 13:52:57 UTC

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