dictionary merge
a new operation
- merge : Dict x Dict --> Dict
- resulting dictionary contains the entries of both dictionaries
- if the argument dictionaries have any common keys, they must agree on their values
- otherwise merge fails
implementation
- note use of special failure value
(define (merge d1 d2)(if (null? d1) d2 (let ((b (car d1)) (k1 (car b)) (v1 (cdr b))) (if (containsKey d2 k1) (if (equal? v1 (lookup d2 k1)) (merge (cdr d1) d2) ‘fail) (cons b (merge (cdr d1) d2)))))))