On Sun, 13 Sep 2009, Abdulaziz Ghuloum wrote:

>
> On Sep 13, 2009, at 11:25 PM, Andre van Tonder wrote:
>
>> On Sun, 13 Sep 2009, Abdulaziz Ghuloum wrote:
>> 
>>> 
>>> On Sep 13, 2009, at 10:55 PM, Andre van Tonder wrote:
>>> 
>>>> No, I think that kind of thing should be required to be an error
>>>> in 1-pass, since it would break the usual lexical scope.
>>> 
>>> If you think
>>> 
>>> (let-syntax ((f (syntax-rules () ((_) 1))))
>>> (let ()
>>>   (define (g) (f))
>>>   (define (f) 2)
>>>   (g)))
>>> 
>>> should be an error, do you also think that
>>> 
>>> (let ([f (lambda () 1)])
>>> (let ()
>>>   (define (g) (f))
>>>   (define (f) 2)
>>>   (g)))
>>> 
>>> should also be an error?
>> 
>> Of course not.
>
> Then I'm not following exactly.  How are you going to handle the
> expression (f) in one pass and still make its f still refer to
> the inner f (that you haven't seen yet)?

By following the example of R6RS and declaring it to be an error.

Two-pass in R6RS has
the same issue, and R6RS handles it in the only consistent way,
namely by declaring it an error.  Below are a bunch of examples
that are errors in two-pass R6RS that are errors for the same
reason, namely that things have been used in expansion that have
not been seen yet.  True, you can make a few more things work in
two-pass that you can in 1-pass, but the exact same problem
rears its head sooner or later, so the choice of number of passes
is really arbitrary.

Andre

R6RS (2-pass) examples that are errors in R6RS:

    ;; This must give an error:

    ;; (let ()
    ;;   (define-syntax foo (lambda (e) (+ 1 2)))
    ;;   (define + 2)
    ;;   (foo))      ; Syntax violation: Definition of identifier that may have
    ;;               ; already affected meaning of undeferred portions of body: 
+

    ;; This gives no error:

    (let ()
      (define-syntax foo (lambda (e) (let ((+ -)) (+ 1 2))))
      (define + 2)
      (foo))         ;==> -1

    ;;(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)))          ; Syntax violation: Definition of identifier that may 
have
    ;;                    ; already affected meaning of undeferred portions of 
body: x

    ;; Still, the following is valid.

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

    ;;(let ((x #f))
    ;;  (let-syntax ((foo (syntax-rules (x)
    ;;                      ((_ x y) (define y 'outer))
    ;;                      ((_ _ y) 1))))
    ;;    (let ()
    ;;      (foo x p)
    ;;      (define x #f)
    ;;      p)))          ; Syntax violation: Definition of identifier that may 
have
    ;;                    ; already affected meaning of undeferred portions of 
body: x

    ;;(let-syntax ((def0 (syntax-rules ()
    ;;                     ((_ x) (define x 0)))))
    ;;  (let ()
    ;;    (def0 z)
    ;;    (define def0 '(def 0))
    ;;    (list z def0))) ; Syntax violation: Definition of identifier that may 
have
    ;;                    ; already affected meaning of undeferred portions of 
body: def0

    ;;(let ()
    ;;  (define define 17)
    ;;  define)        ; Syntax violation: Definition of identifier that may 
have
    ;;                 ; already affected meaning of undeferred portions of 
body: 
define

    ;; (define-syntax foo (syntax-rules () ((_ x) (define x 1))))
    ;;   (let ((b 2))
    ;;     (foo a)
    ;;     (define (foo x) 2)
    ;;     (foo b)
    ;;     (values a b)) ; Syntax violation: Definition of identifier that may 
have
    ;;                   ; already affected meaning of undeferred portions of 
body: foo

    ;; (define-syntax foo (syntax-rules () ((_ x) (define x 1))))
    ;;   (let ()
    ;;     (foo a)
    ;;     (define-syntax foo (syntax-rules () ((_ x) (define x 2))))
    ;;     (foo b)
    ;;     (values a b))  ; Syntax violation: Definition of identifier that may 
have
    ;;                    ; already affected meaning of undeferred portions of 
body: foo

    ;; This should still be valid.

    (let ()
      (define-syntax foo
        (syntax-rules ()
          ((_ def0) (def0 define 17))))
      (foo define)
      0)

    ;; Distinguishing literals from non-literal data:

    (let ()
      (define-syntax list-macro
        (syntax-rules ()
          ((_ x ...) (list x ...))))
      ;; This must give violation:
      ;;(define ... 1)  ; Syntax violation: Definition of identifier that may 
have already
      ;;                ; affected meaning of undeferred portions of body: ...
      ;; But this must not:
      (define list cons)
      (list-macro 1 2))   ;==> (1 . 2)

    ;;(let ()
    ;;  (define-syntax macro
    ;;    (let ((x `(1 ,2)))
    ;;      (lambda (form) x)))
    ;;  (define unquote 2)
    ;;  (macro))    ; Syntax violation: Definition of identifier that may have 
already
    ;;              ; affected meaning of undeferred portions of body: unquote

    ;; Have to make sure that previous does give violation but this does not.
    (let ()
      (define-syntax macro
        (let ((x `(+ ,2)))
          (lambda (form) (cadr x))))
      (define + 2)
      (macro))    ;==> 2



_______________________________________________
r6rs-discuss mailing list
[email protected]
http://lists.r6rs.org/cgi-bin/mailman/listinfo/r6rs-discuss

Reply via email to