<div dir="ltr">Hi Matthias<div><br></div><div>Thanks for the explanation - it helps. I played with the kind of post-condition "broken contract" example that you gave, and find it less problematic, since the blame is local to the function / supplier.</div>
<div><br></div><div>If the error in my original example was reformatted by moving the at clause to the top (easy?) and supplemented with the line number of the guilty client [or supplier] code (hard?) I think it would reduce the confusion and improve the utility. I.e.</div>
<div><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div style="font-size:12.800000190734863px;font-family:arial,sans-serif">twice: contract violation </div><div style="font-size:12.800000190734863px;font-family:arial,sans-serif">
at: .../blame-test.rkt - line 2, column 18</div></div><div><div style="font-size:12.800000190734863px;font-family:arial,sans-serif"> expected: number?</div></div><div><div style="font-size:12.800000190734863px;font-family:arial,sans-serif">
given: 'foo</div></div><div><div style="font-size:12.800000190734863px;font-family:arial,sans-serif"> in: the 1st argument of</div></div><div><div style="font-size:12.800000190734863px;font-family:arial,sans-serif">
(-> number? number?)</div></div><div><div style="font-size:12.800000190734863px;font-family:arial,sans-serif"> contract from: (function twice)</div></div><div><div style="font-size:12.800000190734863px;font-family:arial,sans-serif">
blaming: .../blame-test.rkt - line 6, column 1</div></div><div><div style="font-size:12.800000190734863px;font-family:arial,sans-serif"> </div></div></blockquote><div>What do you think?</div><div><br></div><div>
<br></div><div>Kind regards</div><div><br></div><div>Dan</div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Sep 2, 2013 at 11:48 PM, Matthias Felleisen <span dir="ltr"><<a href="mailto:matthias@ccs.neu.edu" target="_blank">matthias@ccs.neu.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><div><div>
<div>On Sep 2, 2013, at 8:22 AM, Daniel Prager wrote:</div><br><blockquote type="cite"><div dir="ltr"><div>Consider this file:</div><div><br></div><div>--------------------------------------------</div><div><div>#lang racket</div>
<div>(define/contract (twice x)</div><div> (-> number? number?)</div><div> (* 2 x))</div>
<div><br></div><div>(twice 'foo)</div></div><div>--------------------------------------------</div><div><br></div><div>When run in DrRacket 5.3.6 this yields the following error:</div><div><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">
<div><div>twice: contract violation</div></div><div><div> expected: number?</div></div><div><div> given: 'foo</div></div><div><div> in: the 1st argument of</div></div><div><div> (-> number? number?)</div></div>
<div><div> contract from: (function twice)</div></div><div><div> blaming: .../blame-test.rkt</div></div><div><div> at: .../blame-test.rkt: 2.18</div></div></blockquote><div><br></div><div>The final line attributes blame to the twice function (line 2, col 18), but clearly the blame in this instance lies with the client code (line 6), consistent with the first six lines of the error message.</div>
</div></blockquote><div><br></div></div></div><div>This is a misinterpretation of the last line. If you read the entire message as a sentence, you will see that the "at: ..." means "this is where you find the contract that was broken". The "expected:"/"given" pairing means that the function was called, it expected a number, and the caller applied it to the symbol 'foo instead. </div>
<div><br></div><div>If you run this program</div><div><br></div><div><div><div>#lang racket</div><div>(define/contract (twice x)</div><div> (-> number? number?)</div></div><div> 'foo)</div><div><br></div>
<div>(twice 2)</div><div><br></div><div>the error message will say </div><div><br></div><div><div>twice: broke its contract</div><div> promised: number?</div><div> produced: 'foo</div><div> in: the range of</div><div>
<div> (-> number? number?)</div><div> contract from: (function twice)</div></div><div> blaming: (function twice)</div><div> at: unsaved-editor665:2.18</div><div><br></div><div>meaning that foo was called, it promised to return a number, but it produced the symbol 'foo instead. </div>
<div><br></div><div>;; --- </div><div><br></div><div>I will admit that you're not the first one who has tripped over this error message [format] and that you aren't the last one. But changing it isn't easy and adding information isn't easy. The problem is that we wish to keep the messages uniform across all functions but not all functions can benefit from the actual contract system. </div>
<span><font color="#888888"><div><br></div><div>-- Matthias</div></font></span></div></div></div></div></blockquote></div><div dir="ltr"><div style="font-family:arial;font-size:small"></div></div>
</div></div>