[plt-scheme] Contract question

From: pedro pinto (pedro.e.pinto at gmail.com)
Date: Mon Jan 23 16:11:53 EST 2006

Very nice. Thank you.
-pp



On 1/23/06, Robby Findler <robby at cs.uchicago.edu> wrote:
>
> You have to use the more complex combinators to express that. Here's
> how ->r can be used to express map's contract:
>
> (module map-c mzscheme
> (require (lib "contract.ss"))
>
> (define map-c map)
>
> (provide/contract
>   [map-c
>    (->r ([func
>           (and/c
>            procedure?
>            (let ([arity-matches-lists
>                   (λ (f)
>                     (procedure-arity-includes? f (+ 1 (length
> rest-args))))])
>              arity-matches-lists))]
>          [lst-one (listof any/c)])
>         rest-args
>         (and/c (listof (listof any/c))
>                (let ([same-length-lists (λ (x) (apply equal? (length
> lst-one) (map length x)))])
>                  same-length-lists))
>         (listof any/c))]))
>
> (require map-c)
>
> (define (print-msg exn)
> (display (exn-message exn))
> (newline))
>
> (map-c (lambda (x y) x) (list 1 2 3) (list 4 5 6))
> (with-handlers ([values print-msg])
> (map-c (lambda (x) x) (list 1 2 3) (list 4 5 6)))
> (with-handlers ([values print-msg])
> (map-c (lambda (x y) x) (list 1 2 3) (list 4 5 6 7)))
>
> At Mon, 23 Jan 2006 19:49:34 +0000, pedro pinto wrote:
> > Hi there,
> >
> > I just started fumbling around with contracts and I was trying to write
> a
> > contract for a function similar to map:
> >
> > map proc clist1 clist2 ... -> list
> >
> > Is there a way to say that proc is a procedure whose arity should match
> the
> > number of clist arguments?
> >
> > TIA,
> > -pp
> > _________________________________________________
> >   For list-related administrative tasks:
> >   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20060123/32491b98/attachment.html>

Posted on the users mailing list.