On Fri, Apr 17, 2020 at 9:45 AM Ben Greenman <benjaminlgreen...@gmail.com> wrote:
> Hi Marc, > > > >> For contracts, though, (provide (contract-out ...)) gives better error > >> messages than define/contract. > >> > > > > In what sense is this the case, and where can I read more about the > > differences, as well as how to improve errors of contracts? > > contract-out gives better error messages than define/contract in the > sense that it has better blame > > A define/contract needs to immediately decide who could be blamed for > future errors --- because the new definition can be used right away. > > A contract-out can wait until another module requires the definition > --- and tailor its blame errors to different clients. > My understanding is that contract-out only provides protection against inappropriate calls from clients *outside* the module, whereas define/contract enforces the contract against everyone, including things inside the module. Do I have that right? If so, I feel much more comfortable using the latter even if its error messages are not quite as good. On a related topic, I don't understand the concept of positive and negative blame. Can someone fill me in? > Here's an example to play with. Submod A provides two functions: f0 is > made with define/contract and f1 with contract-out. > > ``` > #lang racket > > (module A racket > (define/contract (f0 x) > (-> natural? natural?) > x) > > (define (f1 x) > x) > > (provide f0) > (provide (contract-out [f1 (-> natural? natural?)]))) > > (module B racket > (require (submod ".." A)) > (f0 'hello) > #;(f1 'hello)) > > (require 'B) > ``` > > If B makes a mistake with f0, the error blames submod A. > But if B makes a mistake with f1, the error blames B. > > > The contract library makes these blame errors internally. I don't > think there's any way to customize short of using `contract` directly. > > > Is it related to this part of the documentation of `contract-out` > > ( > https://docs.racket-lang.org/reference/attaching-contracts-to-values.html#%28form._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._contract-out%29%29 > ) > > - which I admittedly don't understand: > > > > "The implementation of contract-out > > < > https://docs.racket-lang.org/reference/attaching-contracts-to-values.html#%28form._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._contract-out%29%29 > > > > uses syntax-property > > < > https://docs.racket-lang.org/reference/stxprops.html#%28def._%28%28quote._~23~25kernel%29._syntax-property%29%29 > > > > to attach properties to the code it generates that records the syntax of > > the contracts in the fully expanded program. Specifically, the symbol ' > > provide/contract-original-contract is bound to vectors of two elements, > the > > exported identifier and a syntax object for the expression that produces > > the contract controlling the export." > > I was only thinking of the "blaming: ...." part of error messages. > > Both define/contract and contract-out can print the whole contract; I > don't think this syntax-property gives contract-out any advantage > > (Sadly, the whole contract is sometimes too big to help me find a problem.) > > -- > You received this message because you are subscribed to the Google Groups > "Racket Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to racket-users+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/racket-users/CAFUu9R5BMG5ZFVrddrJ-6uceV%2B3936ZudE-8ESObycw9B%2BRjcg%40mail.gmail.com > . > -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/CAE8gKof2M%2BHuCf%2B2hfTKbVxCxGEb1Vtx%2BaXehYNZXhttpgMNPA%40mail.gmail.com.