[racket] bound-identifier=? of identifiers with different module-level context

From: Gustavo Massaccesi (gustavo at oma.org.ar)
Date: Tue Aug 28 18:55:04 EDT 2012

I get some strange result when I evaluate if two identifiers with
different module-level context are bound-identifier=?. They don't bind
to each other and it's possible to have a different definition for
each one but the result of bound-identifier=? is #t, but I expect to
get a #f. The macro "expand-to-define-show-twice" defines the two
versions of show, with different module-level context.

If the definitions are inside a local definition context, then the
expansion fails with an error, because when the "define" are
transformed into "letrec" the two identifiers bind each other. I
expect that the results are the same that before.

I'm not sure if I understand correctly the binding rules, but this
looks like a strange border case.

Gustavo


;;; file: define-show-twice.rkt
#lang racket/base
(require (for-syntax racket/base))

(provide (all-defined-out))

{define-syntax (check-bound-identifier=? stx)
  (syntax-case stx ()
    [(_ a b) (datum->syntax stx (bound-identifier=? #'a #'b))])}

{define-syntax (expand-to-define-show-twice stx)
  (with-syntax ([show-good (datum->syntax stx 'show)]
                [show-bad (syntax-local-introduce (datum->syntax
#'here 'show))])
    #'(begin
        (define show-good displayln)
        (define show-bad displayln)
        (show-good "G")
        (show-bad "B")
        (displayln (check-bound-identifier=? show-good show-bad))
        ))}
;;; end file: define-show-twice.rkt


;;; file: example.rkt
#lang racket/base

(require "define-show-twice.rkt")

(expand-to-define-show-twice)
;==> G B #t
;exp. ==> G B #f?

;(let () (expand-to-define-show-twice))
; ==> error: internal definition: duplicate binding name in: show
;exp. ==> G B #f??

;;; end file: example.rkt

Posted on the users mailing list.