t3x.org / sketchy / library / intersection.html
SketchyLISP
Reference
  Copyright (C) 2007
Nils M Holm

intersection

Conformance: SketchyLISP Extension

Purpose: Compute the intersection of sets. Sets are represented by lists of unique members.

Arguments:
A*... - sets

Implementation:

(define (intersection . a*)
  (letrec
    ((_intersection
       (lambda (a b)
         (cond ((null? a) '())
           ((member (car a) b)
             (cons (car a) (_intersection (cdr a) b)))
           (else (_intersection (cdr a) b))))))
    (cond ((null? a*) '())
      (else (fold-left _intersection (car a*) (cdr a*))))))

Example:

(intersection '(a b c) '(b c d) '(c d e)) 
=> (c)

See also:
union, unique, member.