John Thingstad wrote:
> 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
(use srfi-1) ; any
(use srfi-95) ; sort
(define (duplicate-value-check xs)
(define duets (sort (chop xs 2) < last))
(and (pair? xs)
(any
(lambda(a b) (and (equal? (last a) (last b)) (list a b)))
duets
(cdr duets))))
#;13> (duplicate-value-check '(a 2 b 3 c 4 d 5 e 6 f 7 g 8 h 9 i 23))
#f
#;14> (duplicate-value-check '(a 2 b 3 c 4 d 5 e 6 f 7 g 8 h 9 i 2))
((a 2) (i 2))
#;19> (duplicate-value-check '())
#f
#;20> (duplicate-value-check '(x 9))
#f
--
Jews totally run Hollywood.... But I don't care if Americans think we're
running the news media, Hollywood, Wall Street, or the government. I just care
that we get to keep running them. --- Joel Stein
articles.latimes.com/2008/dec/19/opinion/oe-stein19
archive.org/download/DavidDukeTv/DoJewsControlTheMediaTheLaTimesSaysYes.flv