next up previous
Next: 3.2 adjoin Up: 3 集合の表現 Previous: 3 集合の表現

3.1 union, intersection

たとえば,union, intersectionの定義は以下のように書けます.
(defun union (a b &key (test #'eq))
  (cond
   ((null a) b)
   ((member (car a) b :test test)
    (union (cdr a) b :test test))
   (t (cons (car a) (union (cdr a) b :test test)))))
(defun intersection (a b &key (test #'eq))
  (cond
   ((null a) nil)
   ((member (car a) b :test test)
    (cons (car a) (intersection (cdr a) b :test test)))
   (t (intersection (cdr a) b :test test))))


generated through LaTeX2HTML. M.Inaba 平成18年5月6日