[plt-scheme] Question on ill-defined contract
It is a confusing (esp when you come to it from that angle!), yes, but
I think the behavior is correct. The contract only requires that the
function accept three arguments, which it does, so foo-fn does not
break its part of the contract. It does, however, require that callers
supply 3 arguments, which didn't happen.
The confusing part is the error message -- the way the contract system
is implemented, the function that is actually provided by the foo
module only accepts 3 arguments.
I'm not sure I can do better, tho. This is actually a really
interesting case. I'll have to think on it.
Robby
On 6/5/07, Paulo J. Matos <pocm at soton.ac.uk> wrote:
> Hi all,
>
> Today while I was doing a demo on PLT Scheme I hit something I was a
> bit wordless (why does it happen every time were presenting
> something?).
> I defined a function (something along these lines):
> foo.scm
> (module foo mzscheme
>
> (define (foo-fn a b c)
> (+ a b c))
>
> (provide/contract
> [foo-fn (integer? integer? integer? . -> . integer?)]))
>
> Then since the only interesting parameter was a, b was by default 0
> and c was by default a + 5, I changed it to a opt-lambda:
> (define foo-fn
> (opt-lambda (a (b 0) (c (+ a 5)))
> (+ a b c)))
>
> But I forgot to update the contract, when I went to show everyone from
> module bar, how opt-lambda would work nicely, I have:
> (module bar mzscheme
> (require "foo.scm")
> (foo-fn 5))
>
> and I get:
> procedure foo-fn: expects 3 arguments, given 1: 5
>
> The triggered question by the host of the demo was indeed intriguing.
> Shouldn't the contract be broken? Should I get some kind of error
> helping me to spot that the error was in the contract definition?
> When I click the bug I even get a decent error message. Is this a bug
> or a 'feature'?
>
> 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
>