It is the trivial to check for duplicates and lookup key
(defun duplicate-value-check ()
(let* ((values (loop for v in (cdr *enum*) by #'cddr collect v))
(sorted-values (sort values #'<))
(position (mismatch sorted-values
(remove-duplicates sorted-values))))
(when position
(let ((index (nth position sorted-values)))
(error "key ~A has a value ~D duplicated"
(nth (* index 2) *enum*) (nth index sorted-values))))))
Testing with ABCL:
(setq *enum* '(a 2 b 3 c 4 d 5 e 6 f 7 g 8 h 9 i 2))
(duplicate-value-check)
CL-USER(3): Debugger invoked on condition of type SIMPLE-ERROR:
key C has a value 3 duplicated
It should have been:
key i has a value 2 duplicated
Gauche Scheme
(define (dup-check plist)
(let1 seen '()
(do-plist ((k v) plist)
(if (member v seen)
(errorf "Key ~a has dup. value ~a." k v)
(push! seen v)))))
(dup-check '(a 2 b 3 c 4 d 3 e 6 f 7 g 8 h 3 i 42))
*** ERROR: Key d has dup. value 3.
Run-time error: "key I has a value 2 duplicated"
Run-time error: "key D has a value 3 duplicated"
NO-DUPLICATES
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 54 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 16:16:49 |
| Calls: | 742 |
| Files: | 1,218 |
| D/L today: |
3 files (2,681K bytes) |
| Messages: | 184,405 |
| Posted today: | 1 |