[plt-scheme] Contract question

From: pedro pinto (pedro.e.pinto at gmail.com)
Date: Mon Jan 23 18:58:08 EST 2006

 One more question, how would I go about saying something about the return
type of proc/func? From my understanding of the docs I need to write a
function contract, as opposed to what I think is a flat-contract like
arity-matches-lists, but I did not see a way to write one that does not also
pin down the arity.

-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/197d1681/attachment.html>

Posted on the users mailing list.