7.6 Gotchas
7.6.1 Using set! to Assign to Variables Provided via provide/contract
The contract library assumes that variables exported via provide/contract are not assigned to, but does not enforce it. Accordingly, if you try to set! those variables, you may be surprised. Consider the following example:
  | ||||||||
  | ||||||||
> (require 'client)  | ||||||||
  | 
Both calls to print-latest print 0, even though the value of x has been incremented (and the change is visible inside the module x).
To work around this, export accessor functions, rather than exporting the variable directly, like this:
  | 
(define (get-x) x)  | 
(define x 0)  | 
(provide/contract [inc-x! (-> void?)]  | 
This is a bug we hope to address in a future release.