<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Sep 2, 2013, at 8:22 AM, Daniel Prager wrote:</div><br class="Apple-interchange-newline"><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>&nbsp; (-&gt; number? number?)</div><div>&nbsp; (* 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>&nbsp;expected: number?</div></div><div><div>&nbsp;given: 'foo</div></div><div><div>&nbsp;in: the 1st argument of</div></div><div><div>&nbsp; &nbsp; &nbsp; (-&gt; number? number?)</div></div>

<div><div>&nbsp;contract from: (function twice)</div></div><div><div>&nbsp;blaming: .../blame-test.rkt</div></div><div><div>&nbsp;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>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.&nbsp;</div><div><br></div><div>If you run this program</div><div><br></div><div><div>#lang racket</div><div>(define/contract (twice x)</div><div>&nbsp; (-&gt; number? number?)</div><div>&nbsp; 'foo)</div><div><br></div><div>(twice 2)</div><div><br></div><div>the error message will say&nbsp;</div><div><br></div><div><div>twice: broke its contract</div><div>&nbsp; promised: number?</div><div>&nbsp; produced: 'foo</div><div>&nbsp; in: the range of</div><div>&nbsp; &nbsp; &nbsp; (-&gt; number? number?)</div><div>&nbsp; contract from: (function twice)</div><div>&nbsp; blaming: (function twice)</div><div>&nbsp; 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.&nbsp;</div><div><br></div><div>;; ---&nbsp;</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.&nbsp;</div><div><br></div><div>-- Matthias</div><div><br></div><div><br></div><div><br></div><div><br></div></div></div></div></body></html>