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

From: Robby Findler (robby at cs.uchicago.edu)
Date: Sun Nov 6 13:49:19 EST 2005

At Sun, 06 Nov 2005 18:09:38 +0100, Jens Axel Søgaard wrote:
> The approach works nicely. I have a small problem
> blaming the right module though.
>
> [ ...]
>
> The error message is:
> 
>    87:2: top-level broke the contract (-> any/c stack stack) it had with
>    stack-signature on push; expected <stack>, given: 43
> 
> Is there a way to get the provide/contract in the definition of
> provide-stack to know, where the (provide-set) is used? I.e. to
> get an error message mentioning super-stack in stead of stack-signature.

This works .... but I don't know if it is the right way to do things.
That syntax-e seems fishy.

provide/contract uses its argument's syntax location to find the
providing parties location. Perhaps it should be using the word
`provide/contract' instead? I'm not sure. 

Maybe Matthew can say if this is good or not.

This is the error message with the code blow

  99:1: top-level broke the contract (-> any/c stack stack) it had with
  super-stack on push; expected <stack>, given: 43

(module stack-signature mzscheme
  (require-for-syntax macro-utilities)
  (provide provide-stack)
  (define-syntax (provide-stack stx)
    (syntax-case stx ()
      [(_)
       (with-syntax ([pvd
                      (datum->syntax-object
                       stx
                       (syntax-e
                        (with-captures stx
                                       (empty head pop push stack?)
                                       (syntax/loc stx
                                         (provide/contract
                                          (empty  stack/c)
                                          (head   (-> stack/c          any/c))
                                          (push   (-> any/c stack/c   stack/c))
                                          (pop    (-> stack/c          any/c))
                                          (stack? (-> any/c            boolean/c)))))))])
         (with-captures stx
                        (empty head pop push stack?)
                        (syntax/loc stx
                          (begin
                            (require (lib "contract.ss"))
                            (define stack/c
                              (flat-named-contract 'stack stack?))
                            (define boolean/c
                              (flat-named-contract 'boolean boolean?))
                            ; this didn't work
                            pvd))))])))

Robby


Posted on the users mailing list.