; Reba Orton
; Programming Assignment 1
; Programming Languages
; Due February 25, 1987
;
; Four functions designed to manipulate sets after the
; fashion of algebraic Union, Intersection, and the slightly
; different Difference and Equality.
; lists are used to represent sets
;
; Union combines all the elements of both sets into one set
; without repeating any element.
;
(defun setunion (a b)
(cond ((null a) b); if a is empty, then b is all there is
((member (car a) b) (setunion (cdr a) b)); else if element of
; a is same as element of b, then skip recursively
(t (cons (car a) (setunion (cdr a) b))))); else keep the
; element of a in resultant list
;
; Intersection is the combination of all mutual elements
; in both sets into one set, again without repeating.
;
(defun setintersect (a b)
(cond ((null a) nil); if a is empty, nil
((member (car a) b); if element in a is a member of b
(cons (car a) (setintersect (cdr a) b))); then keep
(t (setintersect (cdr a) b)))); else skip
;
; Difference is similar to the algebraic notation of A - B,
; any elements of B found in A is subracted from A, but not B
; in other words, B is not affected and a subset of A is created
;
(defun setdiff (a b)
(cond ((null a) nil); if a is empty, nil
((member (car a) b) (setdiff (cdr a) b)); if member, skip
(t (cons (car a) (setdiff (cdr a) b))))); if not, keep
;
; Equality in two sets is defined as both sets having the same
; elements regardless of order or number of said elements.
;
(defun setequal (a b)
(cond ((not (or (setdiff a b) (setdiff b a))) t); opposite of "and"
(t nil))); if different sets, nil
;
; testing
(load "testbeck.txt")
;