1. ;;memberp : Any conspair -> boolean
  2. ;;determines if the element is in the conspair
  3. ;;this will be used for relations
  4. (defun memberp (e l)
  5. (cond ((or (= (car l) e) (= (cdr l) e)) T)
  6. (t nil)))
  7.  
  8.  
  9. ;;set0-helper : String string-relationp -> setp
  10. ;;returns a set of the elements in the relation related to the input String
  11. (defun set0-helper (e r)
  12. (cond ((endp r) nil)
  13. ((memberp e (car r))
  14. (cons (car(car r)) (cons (cdr(car r)) (set0-helper e (cdr r)))))
  15. (t (set0-helper e (cdr r)))))
  16.  
  17.  
  18. ;;list-append : list list -> list
  19. ;;appends the second list onto the first
  20. (defun list-append (list1 list2)
  21. (cond ((endp list1) list2)
  22. (t (cons (car list1) (list-append (cdr list1) list2)))))
  23.  
  24. (assert-event(=(list-append '(1 2 3) '(4 5 6)) '(1 2 3 4 5 6)))
  25.  
  26.  
  27. ;;set0 : string-relationp setp -> setp
  28. ;;returns a set of the elements related to the elements of the original set
  29. (defun set0 (r s)
  30. (cond ((endp s) nil)
  31. (t (list-append (set0-helper (car s) r) (set0 (cdr s) r)))))
  32.  
  33.  
  34. (assert-event (=(set0 (list (cons "Alice" "Mike")
  35. (cons "Mike" "Julia")
  36. (cons "Julia" "Kenny")
  37. (cons "Alice" "Kenny"))
  38. (list "Alice" "Julia"))
  39. (list "Alice" "Mike" "Alice" "Kenny"
  40. "Mike" "Julia" "Julia" "Kenny")))
  41.  
  42. (assert-event (=(set0 (list (cons "Joe" "John")
  43. (cons "Pete" "Joe")
  44. (cons "Luke" "Alice")
  45. (cons "Ashley" "Mike")
  46. (cons "Ashley" "Joe")
  47. (cons "Ryan" "Sarah")
  48. (cons "Mike" "Sarah"))
  49. (list "Mike" "Joe"))
  50. (list "Ashley" "Mike" "Mike" "Sarah"
  51. "Pete" "Joe" "Ashley" "Joe")))
  52.  
  53.  
  54. ;;relation-trans : string-relationp setp -> setp
  55. ;;returns the set of users that they can meet via a sequence of introductions
  56. (defun relation-trans (r s)
  57. (cond ((= s (set0 r s)) s)
  58. (t (relation-trans r (set0 r s)))))