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

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Mon Nov 7 17:02:28 EST 2005

Robby Findler wrote:
> At Sun, 06 Nov 2005 18:09:38 +0100, Jens Axel Søgaard wrote:

>>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. 

It seems this works too. It seems a little less fishy - but it
is quite possible, there are some "sideeffects" I have overlooked.
I wouldn't have thought of it, unless I saw you solution first.

    (module stack-signature mzscheme
      (require-for-syntax macro-utilities)
      (require (lib "contract.ss"))
      (provide provide-stack)
      (define-syntax (provide-stack stx)
        (syntax-case stx ()
           (with-captures stx
             (empty head pop push stack?)
             (quasisyntax/loc stx
                 (require (lib "contract.ss"))
                 (define stack/c
                   (flat-named-contract 'stack stack?))
                 (define boolean/c
                   (flat-named-contract 'boolean boolean?))
                 #,((syntax-local-value #'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)))))))])))

Jens Axel Søgaard

Posted on the users mailing list.