[racket-dev] weird "module: identifier is already imported" error

From: Christos Dimoulas (chrdimo at ccs.neu.edu)
Date: Thu Jun 21 15:52:09 EDT 2012

Hi,

I ran into an error that I can't explain. Do you have any hints about 
what is going on or any suggestions on how to fix it?

In the following code, macros provides alternative forms for require and 
provide, dubbed accept and provide/dispute. They are doing the same job 
as provide and require except that they create a fresh identifier to add 
a little bit of indirection. The first client defines foo and provides 
it with provide/dispute. The other clients just use accept and 
provide/dispute to pass along foo.

When I ran the code I get ''module: identifier is already imported in: 
foo2''.

Thanks.

#lang racket

(module macros racket

   (provide accept provide/dispute)

   (define-syntax (accept stx)
     (syntax-case stx ()
       [(_ spec id)
        (with-syntax ([(new-id) (generate-temporaries #'(id))])
          #`(begin
              (require (only-in spec [id new-id]))
              (define id new-id)))]))

   (define-syntax (provide/dispute stx)
     (syntax-case stx ()
       [(_ id)
        (with-syntax ([(new-id) (generate-temporaries #'(id))])
          #`(begin
              (define new-id id)
              (provide (rename-out [new-id id]))))])))

(module client1 racket

   (require (submod ".." macros))

   (define (foo x) x)

   (provide/dispute foo))

(module client2 racket

   (require (submod ".." macros))

   (accept (submod ".." client1) foo)

   (provide/dispute foo))

(module client3 racket

   (require (submod ".." macros))

   (accept (submod ".." client2) foo)

   (provide/dispute foo))



Posted on the dev mailing list.