+;;;; Copyright (c) 2013 Robert Smith
+;;;; Implementations of PARTITION-IF and EQUIVALENCE-CLASSES.
+(defun partition-if (f list)
+ :finally (return (list yes no))))
+(defun partition-if (f seq)
+ "Partition the sequence SEQ into a list of elements satisfying the
+predicate F and a list of elements who do not."
+(defun equivalence-classes (equiv seq)
+ "Partition the sequence SEQ into a list of equivalence classes
+according to the equivalence relation EQUIV."
+ (let ((half-length (floor (length seq) 2))
+ (labels ((find-equivalence-class (x)
+ (find-if (lambda (class)
+ (funcall equiv (aref class 0) x))
+ (make-array half-length
+ (let ((class (find-equivalence-class x)))
+ (vector-push-extend x class)
+ (push (new-class x) classes)))))
+ ;; Partition into equivalence classes.
+ (map nil #'add-to-class seq)