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

I think that's correct. Note though that the implication is that
define/contract could produce a much more expensive code, especially for
recursive function, since it will need to check against the contract for
every iteration.


> On a related topic, I don't understand the concept of positive and
> negative blame.  Can someone fill me in?
>

I always forget which is positive and negative, so I won't use the terms
here (and too lazy to lookup). But roughly, suppose you attach a function
contract (-> number? string?) to a function value, then there are mainly
two ways things could go wrong.

1. Client uses the function incorrectly by calling it with non-number.
2. The function itself returns a non-string.

A blame would indicate whose party is at fault when a contract is
violated--caller or the function itself.


>
>
>> 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
> <https://groups.google.com/d/msgid/racket-users/CAE8gKof2M%2BHuCf%2B2hfTKbVxCxGEb1Vtx%2BaXehYNZXhttpgMNPA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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/CADcuegskOV0cOQ8xYjTmbED2XA8dvZj9OkY_aFP0_7d28Lho3g%40mail.gmail.com.

Reply via email to