;;memberp : Any conspair -> boolean
;;determines if the element is in the conspair
;;this will be used for relations
(defun memberp (e l)
(cond ((or (= (car l) e) (= (cdr l) e)) T)
(t nil)))
;;set0-helper : String string-relationp -> setp
;;returns a set of the elements in the relation related to the input String
(defun set0-helper (e r)
(cond ((endp r) nil)
((memberp e (car r))
(cons (car(car r)) (cons (cdr(car r)) (set0-helper e (cdr r)))))
(t (set0-helper e (cdr r)))))
;;list-append : list list -> list
;;appends the second list onto the first
(defun list-append (list1 list2)
(cond ((endp list1) list2)
(t (cons (car list1) (list-append (cdr list1) list2)))))
(assert-event(=(list-append '(1 2 3) '(4 5 6)) '(1 2 3 4 5 6)))
;;set0 : string-relationp setp -> setp
;;returns a set of the elements related to the elements of the original set
(defun set0 (r s)
(cond ((endp s) nil)
(t (list-append (set0-helper (car s) r) (set0 (cdr s) r)))))
(assert-event (=(set0 (list (cons "Alice" "Mike")
(cons "Mike" "Julia")
(cons "Julia" "Kenny")
(cons "Alice" "Kenny"))
(list "Alice" "Julia"))
(list "Alice" "Mike" "Alice" "Kenny"
"Mike" "Julia" "Julia" "Kenny")))
(assert-event (=(set0 (list (cons "Joe" "John")
(cons "Pete" "Joe")
(cons "Luke" "Alice")
(cons "Ashley" "Mike")
(cons "Ashley" "Joe")
(cons "Ryan" "Sarah")
(cons "Mike" "Sarah"))
(list "Mike" "Joe"))
(list "Ashley" "Mike" "Mike" "Sarah"
"Pete" "Joe" "Ashley" "Joe")))
;;relation-trans : string-relationp setp -> setp
;;returns the set of users that they can meet via a sequence of introductions
(defun relation-trans (r s)
(cond ((= s (set0 r s)) s)
(t (relation-trans r (set0 r s)))))