On 10/29/20, William J. Bowman <
w...@williamjbowman.com> wrote:
> I'm considering implementing, maybe as a library or a pull-request to
> racket/dict, contracts for (partially) specifying which keys exist in a
> dictionary and a contract for the value on that key.
Great!
Please make the contract error messages point out the bad key and bad
value. The error messages from hash/dc are usually too big for me, and
I end up moving my key-check and value-check contracts into a function
that checks things one-by-one.
(Maybe hash/dc can give better errors ... I never looked into a fix.)
> I've got a quick prototype here:
>
>
https://gist.github.com/wilbowma/7e97c8a38130c720568d008b288466f0
>
> (dictof (id expr) ...)
> A contract for a dictionary that contains exactly the keys id ... that map
> to
> values that satisfy the contracts expr ... (respectively).
>
> (rho-dictof (id expr) ...)
> A contract for a dictionary that contains at least the keys id ... that
> map to
> values that satisfy the contracts expr ... (respectively).
>
> Before I start documenting and making it a thing, I thought I'd solicit
> feedback.
Two comments:
1. make these functions, not macros
2. make "at least" the default behavior for dictof, add an option to
override (#:exact-keys?), and remove rho-dictof