[plt-scheme] improving arity checks in contracts

From: Danny Yoo (dyoo at hkn.eecs.berkeley.edu)
Date: Fri Jul 14 17:01:23 EDT 2006

Hi everyone,


I've been chasing down a bug in my code that had to do with breaking a 
contract, but the contract system didn't help too much in finding the 
proper party to blame.  Here's an example where the contracts don't 
properly blame the provider:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> (module foo mzscheme
     (require (lib "contract.ss"))
     (provide/contract (q/r (number? number? . -> . number?)))
     (define (q/r a b)
       (values (quotient a b) (remainder a b))))
> (require foo)
> (q/r 3 4)
context expected 1 value, received 2 values: 0 3

  === context ===
repl-loop
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

The bug in my code here is obvious: the contract is wrong.  But the error 
message that comes out could be a lot more helpful.  I hope contract.ss 
can be easily amended to check this; I'm starting to heavily use 
let-values, and I'm making a lot of mistakes that the contract system 
should blame me with... *grin*


Thanks!


Posted on the users mailing list.