[plt-scheme] Interaction of contract library and WebIt

From: Dave Herman (dherman at ccs.neu.edu)
Date: Sat Dec 17 23:07:24 EST 2005

> Just fixed a fun bug where the contract library's ->
> operator was conflicting with WebIt's use of the same in
> pattern matching.  Methinks this is some macro problem,
> probably triggered by lack of hygiene.  My usual technique

This kind of problem is usually caused by the literals list of macros. 
When a macro matches against an identifier from its literals list, the 
comparison implicitly used is "module-identifier=?". Roughly, two 
identifiers are considered to be module-identifier=? if they either 
refer to the same binding, or are unbound and symbolically equal (IIRC).

As a consequence, whatever binding the identifier -> has at the place 
where xml-match is defined, the same binding must be in place for -> at 
the point of usage of xml-match to get proper behavior. Most likely, -> 
is unbound at the point of definition of xml-match, so if your code 
binds ->, then xml-match no longer behaves correctly. Requiring the 
contract library binds -> and so you get the error.

You aren't gonna like this, but you could do the following:

     (require (prefix contract: (lib "contract.ss")))
     (provide/contract [foo (bar? . contract:-> . baz?)])

or perhaps

     (require (all-except (lib "contract.ss") ->))
     (require (rename (lib "contract.ss") --> ->))
     (provide/contract [foo (bar? . --> . baz?)])

What's annoying about all this is that it forces you to know something 
about the set of bindings at the point of definition of some other 
library's code (in this case, xml-match), which you don't necessarily 
have access to (or want to have to bother with). The moral: literals 
lists considered problematic.

For reference, here is one way macro implementors can avoid the problem:



Posted on the users mailing list.