[plt-scheme] contract question

From: Dave Gurnell (d.j.gurnell at gmail.com)
Date: Wed Feb 6 08:04:48 EST 2008

I'm not sure why you can't use or/c (see below), but you should be  
able to use ->* or case->:

     (define (example a (b #f))
       (if b (+ a b) (void)))

->* specifies contracts for variable arity procedures:

     (provide/contract
      (example (->* (number?) (number?) (or/c number? void?))))

case-> is intended for contracts on case-lambdas, but it should work  
okay here:

     (provide/contract
      (example (case-> (-> number? number? number?)
                       (-> number? void?))))

I thought or/c could only be used on value contracts but the  
documentation suggests otherwise.

Cheers,

-- Dave

> Finally I decided to try contracts. I tried:
>
> #| require one or two numbers
>    promise to return a number if two numbers are given
>    promise void if one number is given |#
>
> #lang scheme
>
> (provide/contract
>  (example
>   (or/c
>    (-> number? number? number?)
>    (-> number? void?))))
>
> (define (example a (b #f))
>  (if b (+ a b) (void)))
>
> This compiles, but it wont run:
>
> Welcome to DrScheme, version 3.99.0.10-svn4feb2008 [3m].
> Language: Module custom.
> or/c: two arguments, (-> number? void?) and (-> number? number?  
> number?), might both match #<procedure:example>
>
> Why? What is wrong in my contract? May be I am wanting an impossible  
> contract?
> or/c repeats exactly what I want, but does not accept it.
> I think I am missing something fundamental, but I can't find an  
> answer in the docs.
> Thanks, Jos Koot
> _________________________________________________
>  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/20080206/9647c1d2/attachment.html>

Posted on the users mailing list.