[plt-scheme] Re: function contracts
Robby Findler wrote:
> You need to use ->*, put the arguments into the list part and check the
> length of the list manually, for now.
In this case the function must be defined to take any number of arguments, but
I'd like to provide such a contract on a procedure of arity 2 without changing
the procedure's definition. Is this possible?
For example, consider a variant of srfi 1's zip that is defined only for two
lists, which must be of equal length.
(define (zip2 ls1 ls2) (map list ls1 ls2))
The following contract will not work:
(() (lambda (ls) (and (= 2 (length ls))
(= (length (car ls))
(length (cadr ls)))))
. ->d* . (lambda in (lambda (out)
(and (list? out)
(= (length out) (length (car in)))))))
But had we defined zip2 as (define zip2 (lambda ls (apply map list ls)))
things work fine. Unfortunately, I don't have the option to rewrite the
procedures I'm interested in.
Thanks,
David