Identifier created by datum->syntax can't be referred properly

Create issue
Issue #89 resolved
Takashi Kato repo owner created an issue

Related issue with #88 (separated for tracking)

The issue #88 was created for (getopt). This issue is for the root cause. #88 resolves this issue partially to treat toplevel identifier specially. However it doesn't resolve the following case:

(let ()  
  (define-syntax let-it
    (lambda (x)
      (define (bind-it k binding)
    (syntax-case binding ()
      ((var . val) 
       (let ((n (syntax->datum #'var)))
         #`(#,(datum->syntax k n) val)))
      (_ (error 'let-it "invalid form"))))
      (syntax-case x ()
    ((k ((var . val) rest ...) body ...)
     (with-syntax (((var1 val1) (bind-it #'k #'(var . val))))
       #'(let ((var1 val1))
           (let-it (rest ...) body ...))))
    ((_ () body ...)
     #'(begin body ...)))))

  (let-it ((name . 'name)) (test-equal "datum->syntax(2)" 'name name))
  )

This can be resolve by comparing identifier envs in sense of eq? (or equal?) however doing so introduces other macro related issue (bending scope). Resolving this properly requires proper re-write mechanism for identifier like followings:

  • all bound identifier should be renamed during complation time by compiler (e.g. let)
  • variable look up should compare identifier by its environment.

NOTE: If we do above, then it would cost O(n^2) time per compilation unit and we don't want it. So we need something else to resolve this issue.

Comments (1)

  1. Takashi Kato reporter

    Changing er-rename not to lookup before renaming. Adding identifier identity slot to determine whether identifiers are the same bound or not. Adding different bound test case. Fixes #89 Fixes #92

    → <<cset 4f7dbb94ab8b>>

  2. Log in to comment