> Ben: if you have an example of the bad hash/dc error message I'd be
> interested to see it.
>
> Robby

Here's the kind of message that turned me off:

```
ctc.rkt:34:0: broke its own contract
  promised: (hash/dc (k (or/c (quote a) (quote b) (quote c))) (v (k)
(config-value/c k)) #:immutable #t #:kind (quote flat))
  produced: '#hash((a . 1) (b . #t) (c . #<void>))
  in: (hash/dc
       (k (or/c 'a 'b 'c))
       (v (k) (config-value/c k))
       #:immutable
       #t
       #:kind
       'flat)
  contract from: +
  blaming: +
   (assuming the contract is correct)
```

It prints the whole hash and contract, leaving me to figure out the
two key parts: (1) what piece of the hash failed, and (2) what the
contract expected for that piece.

Now that I think of it ->* is bad in the same way --- especially for
`plot` functions.


Here's the code that made that error message. The #;(lambda ....)
comment is the contract that I ended up using instead of hash/dc (it
still doesn't explain bad values well).

```
#lang racket/base

(require racket/contract)

(provide config/c)

(define config-key/c
  (or/c 'a 'b 'c))

(define (config-value/c k)
  (case k
    ((a)
     string?)
    ((b)
     boolean?)
    ((c)
     void?)))

(define config/c
  #;(lambda (h)
    (for ((k (in-list (list 'a 'b 'c))))
      (unless (hash-has-key? h k)
        (raise-arguments-error 'config/c "missing key" "key" k "hash" h))
      (define v (hash-ref h k))
      (unless ((config-value/c k) v)
        (raise-arguments-error 'config/c "bad value for key" "key" k
"value" v "hash" h))
      (void)))
  (hash/dc
    [k config-key/c]
    [v (k) (config-value/c k)]
    #:immutable #true
    #:kind 'flat))

(contract
  config/c
  (hash 'a 1 'b #true 'c (void))
  '+
  '-)
```

-- 
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/CAFUu9R61khGypp61r6A4i%2BrO8C7O%3D4TLy23KdF9aOpeeSy_4UQ%40mail.gmail.com.

Reply via email to