Opened 5 years ago

Last modified 3 years ago

#1441 closed defect

Macro keywords unexpectedly match against imported identifiers — at Initial Version

Reported by: sjamaan Owned by: sjamaan
Priority: major Milestone: 5.1
Component: expander Version: 4.13.0
Keywords: hygiene, syntax-rules, capture Cc:
Estimated difficulty: hard


As reported by Joerg Wittenberger, Al Petrofsky's "unhygienic extraction" of identifiers via syntax-rules keywords list fails when the identifier was imported from another module.

A simplified example:

(module break (break)
  (import scheme)
  (define break "elsewhere"))

(module unhygienic-loop (loop)
  (import scheme)

(define-syntax find-identifier
  (syntax-rules ()
    ((_ ident (x . y) sk fk)
     (find-identifier ident x sk (find-identifier ident y sk fk)))
    ((_ ident #(x ...) sk fk)
     (find-identifier ident (x ...) sk fk))
    ((_ ident form sk fk)
           (syntax-rules (ident)
             ((_ ident ident* (s-f . s-args) fk_) (s-f ident* . s-args))
             ((_ x y sk_ fk_) fk_))))
       (check form form sk fk)))))

(define-syntax loop
  (syntax-rules ()
    ((_ . exps)
         ((l (syntax-rules ()
               ((_ ident exps_)
                 (lambda (ident)
                   (let f ()
                     (begin 'prevent-empty-begin . exps_)
       (find-identifier break exps (l exps) (l bogus exps)))))))

(module foo ()

(import scheme break unhygienic-loop)

;; Uncomment these and comment the above to see the differing behaviour:
;; (import scheme unhygienic-loop)

;; This definition is not required
;; (define break "local")

(display (loop (break 'foo))))

This appears to be incorrect, at least when compared to Chibi on an equivalent set of R7RS modules, it behaves identically in the case where the identifier is defined locally, undefined, or defined by another module.

Change History (0)

Note: See TracTickets for help on using tickets.