[plt-scheme] function contracts
>
>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