Trying to understand contracts. Looking at https://docs.racket-lang.org/guide/contracts-first.html I am in equal parts awestruck and disheartened — is that the expectation in terms of depth and complexity? It seems like contracts like that would exceed the complexity of the function implementation itself. Also, presumably contracts that validate every assumption made by the function would impact the performance?
The guide seems intentionally over-engineering the contract to show all the possibilities, I guess.
For what it’s worth, I personally never had to write such complex contracts.
I have used dependant contracts but never to the level of complexity in that example
I think my expectation would be to specify the signature, but leave the invariants to unit tests.
The guide there is showing a bunch of different variants of the contract, to show different possibilities. You can of course choose which level you want to specify contracts to.
Feeling pleased with having discovered I can do this: (set-add! (hash-ref! ht key mutable-set) value)
Like Python’s defaultdict(set)
And there’s even a recommendation in the racket style guide about how to do that best: contacts by default, and add a no-contract
submodule
@stefan.kruger Huh, that looks like a mutable multidict https://docs.racket-lang.org/rebellion/Multidicts.html