[racket] Confusing blame message
On Sep 2, 2013, at 8:22 AM, Daniel Prager wrote:
> Consider this file:
>
> --------------------------------------------
> #lang racket
> (define/contract (twice x)
> (-> number? number?)
> (* 2 x))
>
> (twice 'foo)
> --------------------------------------------
>
> When run in DrRacket 5.3.6 this yields the following error:
>
> twice: contract violation
> expected: number?
> given: 'foo
> in: the 1st argument of
> (-> number? number?)
> contract from: (function twice)
> blaming: .../blame-test.rkt
> at: .../blame-test.rkt: 2.18
>
> 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.
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.
If you run this program
#lang racket
(define/contract (twice x)
(-> number? number?)
'foo)
(twice 2)
the error message will say
twice: broke its contract
promised: number?
produced: 'foo
in: the range of
(-> number? number?)
contract from: (function twice)
blaming: (function twice)
at: unsaved-editor665:2.18
meaning that foo was called, it promised to return a number, but it produced the symbol 'foo instead.
;; ---
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.
-- Matthias
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20130902/cee3e817/attachment-0001.html>