[plt-scheme] Question on ill-defined contract

From: Paulo J. Matos (pocm at soton.ac.uk)
Date: Tue Jun 5 17:46:48 EDT 2007

On 6/5/07, Robby Findler <robby at cs.uchicago.edu> wrote:
> 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.
>

And is there anything in the contract implementation to make this
happen only during a demonstration where everyone is trying to kill
PLT Scheme?!? ;-)

Anyway, thanks for the explanation. I thought that the foo-fn provided
by the module would only accept 3 arguments due to contract
specification. What I didn't really expect was the message to be so
contract-less in terms of information, because if contract wraps
foo-fn and exports it only to accept 3 arguments, the message expected
would be that bar broke the contract of foo-fn when calling it with
only 1 argument.

> 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
> >
>
>
>


-- 
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.