[plt-scheme] function contracts

From: Zhu Chongkai (mathematica at citiz.net)
Date: Thu Mar 11 04:18:24 EST 2004

>
>Is it possible to define a function contract that will cause some constraint
>to hold between the arguments of the function?  For example a function might
>require two integer arguments where the first must be less than the second.  I
>couldn't see how to do this from reading the documentation.
>
>Thanks,
>David
>

DrScheme treat contract as *comments*. The purpose of writing commentary text 
is to help people (both writer and reader) to understand the code. 

If you want a function to force its first argument be less than the second, you 
can write this in the body of the function:

;; a-fun : integer integer -> ???
;; the first argument must be less than the second
(define (a-fun a b)
  (cond ((< a b)
         ... the body ...
         else
         ... report the error ...)))


Zhu Chongkai
mathematica at citiz.net




Posted on the users mailing list.