[plt-scheme] Contracts: having ->r and opt->

From: Paulo J. Matos (pocm at soton.ac.uk)
Date: Sun Apr 8 15:59:55 EDT 2007

On 4/8/07, Noel Welsh <noelwelsh at yahoo.com> wrote:
> Appears not:
>
> (require (lib "contract.ss")
>          (lib "etc.ss"))
>
> (define/contract foo
>   (->r ((x number?) (y (>/c x))) z (cons/c number? null?) any)
>   (opt-lambda (x y [z 0])
>     (+ x y z)))
>
> [bug] 3:3: foo broke the contract
>   (->r ((x ...) (y ...)) z ... ...)
> on foo; expected a procedure that accepts 2 arguments and aribtrarily more (not arity (2 3)), got  #<procedure:foo>
>
> The only alternative I can see is to use case->, but the docs say ->r is not allowed as an alternative in case->:
>
>
> The case-> expression constructs a contract for
> case-lambda function. It's arguments must all be function
> contracts, built by one of ->, ->d,
> ->*, or ->d*.
>
> Except the docs lie:
>
> (define/contract foo
>   (case->
>    (->r ((x number?) (y (>/c x))) any)
>    (->r ((x number?) (y (>/c x)) (z number?)) any))
>   (opt-lambda (x y [z 0])
>     (+ x y z)))
>

Indeed, case-> works very well in this case, thank you.

> > (foo 1 2 3)
> 6
> > (foo 1 2)
> 3
> > (foo 2 1)
> [bug] 7:3: 7:2 broke the contract
>   (case->
>     (->r ((x ...) (y ...)) ...)
>     (->r ((x ...) (y ...) (z ...)) ...))
> on foo; expected <(>/c 2)>, given: 1
> >
>
> I guess this is an oversight in the documentation of the contract language
>
>
> N.
>
>
> ----- Original Message ----
> From: Paulo J. Matos <pocm at soton.ac.uk>
> To: PLT-list Mailing <plt-scheme at list.cs.brown.edu>
> Sent: Sunday, April 8, 2007 11:10:18 AM
> Subject: [plt-scheme] Contracts: having ->r and opt->
>
> Hello all,
>
> Is it possible to have contracts for opt-lambda which arguments depend
> on each other?
>
> For example:
> (define foo
>    (opt-lambda (x y [z 0])
>     ....))
>
> x, y and z should be numbers and y should be bigger than x. Is it
> possible to say this in a contract?
>
> Cheers,
>
> --
> Paulo Jorge Matos - pocm at soton.ac.uk
> http://www.personal.soton.ac.uk/pocm
> PhD Student @ ECS
> University of Southampton, UK
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
>
>
>
>
>
> ____________________________________________________________________________________
> Be a PS3 game guru.
> Get your game face on with the latest PS3 news and previews at Yahoo! Games.
> http://videogames.yahoo.com/platform?platform=120121
>
>
>


-- 
Paulo Jorge Matos - pocm at soton.ac.uk
http://www.personal.soton.ac.uk/pocm
PhD Student @ ECS
University of Southampton, UK


Posted on the users mailing list.