[plt-scheme] Some contract advice

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Sun Mar 22 12:13:46 EDT 2009

Swap the contracts. Otherwise length can blow up on you when the  
input is 10 or the output is 42.


On Mar 22, 2009, at 12:01 PM, Grant Rettke wrote:

> Is the best way to write a contract for a function that takes a list
> of natural numbers of length >= 2 and outputs a list of natural
> numbers that is the same length as the input?
>
> (->d
>      ([argument (and/c (flat-named-contract
>                         'arg-len->=2-required
>                         (λ (ls) (>= (length ls) 2)))
>                        (listof natural-number/c))])
>      ()
>      (result (and/c (flat-named-contract
>                      'res-len-must-match-arg-len
>                      (λ (ls) (= (length ls) (length argument))))
>                     (listof natural-number/c))))
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme



Posted on the users mailing list.