chickadee » srfi-1 » lset-intersection

lset-intersection = list_1 list_2 ...procedure

Returns the intersection of the lists, using = for the element-equality procedure.

The intersection of lists A and B is comprised of every element of A that is = to some element of B: (= A B), for A in A, and B in B. Note this implies that an element which appears in B and multiple times in list A will also appear multiple times in the result.

The order in which elements appear in the result is the same as they appear in LIST_1 -- that is, lset-intersection essentially filters LIST_1, without disarranging element order. The result may share a common tail with LIST_1.

In the n-ary case, the two-argument list-intersection operation is simply folded across the argument lists. However, the dynamic order in which the applications of = are made is not specified. The procedure may check an element of LIST_1 for membership in every other list before proceeding to consider the next element of LIST_1, or it may completely intersect LIST_1 and LIST_2 before proceeding to LIST_3, or it may go about its work in some third order.

(lset-intersection eq? '(a b c d e) '(a e i o u)) => (a e)
 
;; Repeated elements in LIST1 are preserved.
(lset-intersection eq? '(a x y a) '(x a x z)) => '(a x a)
 
(lset-intersection eq? '(a b c)) => (a b c)     ; Trivial case