[racket] Re-providing contracted structs?

From: J. Ian Johnson (ianj at ccs.neu.edu)
Date: Thu Jul 21 10:25:20 EDT 2011

After chatting with samth, I know the deal here.
Provided identifiers are only the same in symbol, but not free-identifier=?.
provide/contract creates mangled identifiers and provides them rename-out'd to the original identifier. This does NOT make the provided identifier free-identifier=? to the original - they are free-identifier=? to the mangled ids.

The way I went about fixing this was to use an unhygienic macro so that I could capture that mangled id when expanding in the other module.
(define-syntax (myprovide stx)
 (syntax-case stx ()
   [(_ param)
    (with-syntax ([mystruct (datum->syntax #'param 'mystruct)])
      #'(begin (provide/contract [a param])
               (provide (struct-out mystruct))))]))

-Ian
----- Original Message -----
From: "J. Ian Johnson" <ianj at ccs.neu.edu>
To: "users" <users at racket-lang.org>
Sent: Wednesday, July 20, 2011 8:42:05 PM GMT -05:00 US/Canada Eastern
Subject: [racket] Re-providing contracted structs?

I have a strange bug I can't figure out dealing with re-providing a struct that was contracted in my require.

Module A:
Firstly, I have a specific contract for my struct:
(provide/contract (struct mystruct ([field integer?])))

I have another part of A I will contract later:
(provide a)

I have several other modules that give a, b and c in module A different contracts, but only slightly, so I have a macro for it in module A.

(define-syntax-rule (myprovide param)
 (begin (provide/contract [a param])
        (provide (struct-out mystruct))))

Module B:
[require module A]

(myprovide any/c)

ERROR:
struct-out: no binding for structure-type identifier at: mystruct in: (struct-out mystruct)

This works if Module A just does (provide (struct-out mystruct)), but I don't want that.
Is it really the case that I can't re-export this struct using struct-out, or is there a bug in provide/contract?

-Ian
_________________________________________________
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users


Posted on the users mailing list.