[plt-scheme] Problem with macro generated provide/contract

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Sat Nov 5 16:14:43 EST 2005

Hi all,

This is a simple implementation of lists:

(module mylist1 mzscheme
   (define mycons cons)
   (define myempty '())
   (define mycar car)

   (provide mycons myempty mycar))


Adding contracts this become:

(module mylist1-with-contracts mzscheme
   (define mycons cons)
   (define myempty '())
   (define mycar car)

   (require (lib "contract.ss"))
   (define pair/c (flat-named-contract 'pair pair?))
   (provide/contract
    (mycons (any/c any/c  . -> .  pair/c))
    (mycar  (pair/c  . -> . any/c))))


Now, the above implementation might not be the best,
so we decide to implement the list datatype with
other underlying representations. The implementations
share the provided names, so these are put in a
"signature".

(module list-signature mzscheme
   (provide provide-list-operations)
   (define-syntax provide-list-operations
     (syntax-rules ()
       [(provide-list-operations)
        (provide mycons mycar myempty)])))

Our original mylist1 without signatures now become:

(module mylist2 mzscheme
   (define mycons cons)
   (define myempty '())
   (define mycar car)

   (require list-signature)
   (provide-list-operations))


But here is what happens when contracts enter the picture:

(module list-signature-with-contracts mzscheme
   (provide provide-list-operations-with-contracts)
   (define-syntax provide-list-operations-with-contracts
     (syntax-rules ()
       [(provide-list-operations-with-contracts)
        (begin
          (require (lib "contract.ss"))
          (define pair/c (flat-named-contract 'pair pair?))
          (provide/contract
           (mycons (-> any/c any/c  pair/c))
           (mycar  (-> pair/c  any/c)))
          (provide myempty))])))


(module mylist2-with-contracts mzscheme
   (define mycons cons)
   (define myempty '())
   (define mycar car)

   (require list-signature-with-contracts)
   (provide-list-operations-with-contracts))

This gives the error

     expand: unbound variable in module in: mycons

Is there a trick to overcome this problem?

-- 
Jens Axel Søgaard





Posted on the users mailing list.