Quick example:
(defun foo ( l f / r z )
(foreach x (reverse l)
(if (vl-some '(lambda ( y ) (if (apply f (list x (car y))) (setq z y))) r)
(setq r (subst (cons x z) z r))
(setq r (cons (list x) r))
)
)
)
_$ (setq attdata '((6 4 "A") (6 4 "B") (18 11 "A") (18 11 "A") (18 11 "C") (18 12 "C") (22 6 "T") (22 6 "M")))
(
( 6 4 "A")
( 6 4 "B")
(18 11 "A")
(18 11 "A")
(18 11 "C")
(18 12 "C")
(22 6 "T")
(22 6 "M")
)
_$ (foo attdata '(lambda ( a b ) (and (= (car a) (car b)) (= (cadr a) (cadr b)))))
(
(( 6 4 "A") ( 6 4 "B"))
((18 11 "A") (18 11 "A") (18 11 "C"))
((18 12 "C"))
((22 6 "T") (22 6 "M"))
)