Incorrect variable reference

Issue #61 resolved
Takashi Kato repo owner created an issue

This should raise an error

(import (rnrs))

(define-syntax extract
  (syntax-rules ()
    ((_ symb body _cont)
      (letrec-syntax
    ((tr
           (syntax-rules (symb)
          ((_ x symb tail (cont-head symb-l . cont-args))
           (cont-head (x . symb-l) . cont-args)) ; symb has occurred
          ((_ d (x . y) tail cont)   ; if body is a composite form,
           (tr x x (y . tail) cont)) ; look inside
          ((_ d1 d2 () (cont-head  symb-l . cont-args))
           (cont-head (symb . symb-l) . cont-args)) ; symb does not occur
          ((_ d1 d2 (x . y) cont)
           (tr x x y cont)))))
    (tr body body () _cont)))))

(define-syntax aif
  (syntax-rules ()
    ((_ ?c ?t ?e)
     (let-syntax ((cont
                   (syntax-rules ()
                     ((cont (??it) ??c ??t ??e)
                      (let ((??it ??c))
                        (if ??it ??t ??e))))))
       (extract it (?t . ?e) (cont () ?c ?t ?e))))))

(let ((it 0))
  (aif (assoc 'a '((a . 1) (b . 2) (c . 3)))
     (display it)
     #f))

Comments (2)

  1. Takashi Kato reporter

    The issue is in match-pattern? procedure. Inside of it, compare is defined and checks if the given variable is literal or not. The literal check must be done in sense of free-identifier=? however it does check global binding check by name and defined library. This is wrong however if we remove that part it breaks other macro expansion. We need something better idea not to break.

  2. Takashi Kato reporter

    Considering bound template variable. (Fixes #61) This is rather dirty fix. If a template variable is bound in usage env but not in macro env, then this should not refer the usage env variable. However current p1env-lookup doesn't care about it so that the variable is resolved as a bound identifier. To avoid this renaming template variable considers where it's bound and if it's not bound macro env then it truncate the identifier frame.

    → <<cset a2ce420cab8e>>

  3. Log in to comment