sets.red 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. %
  2. % SETS.RED - Functions acting on lists as sets
  3. %
  4. % Author: Eric Benson
  5. % Symbolic Computation Group
  6. % Computer Science Dept.
  7. % University of Utah
  8. % Date: 12 December 1981
  9. % Copyright (c) 1981 University of Utah
  10. %
  11. lisp procedure List2Set L; %. Remove redundant elements from L
  12. if not PairP L then NIL
  13. else if car L member cdr L then List2Set cdr L
  14. else car L . List2Set cdr L;
  15. lisp procedure List2SetQ L; %. EQ version of List2Set
  16. if not PairP L then NIL % Don't confuse it with SetQ!
  17. else if car L memq cdr L then List2Set cdr L
  18. else car L . List2Set cdr L;
  19. lisp procedure Adjoin(Element, ASet); %. Add Element to Set
  20. if Element member ASet then ASet else Element . ASet;
  21. lisp procedure AdjoinQ(Element, ASet); %. EQ version of Adjoin
  22. if Element memq ASet then ASet else Element . ASet;
  23. lisp procedure Union(X, Y); %. Set union
  24. if not PairP X then Y
  25. else Union(cdr X, if car X Member Y then Y else car X . Y);
  26. lisp procedure UnionQ(X, Y); %. EQ version of UNION
  27. if not PairP X then Y
  28. else UnionQ(cdr X, if car X memq Y then Y else car X . Y);
  29. lisp procedure XN(U, V); %. Set intersection
  30. if not PairP U then NIL
  31. else if car U Member V then car U . XN(cdr U, Delete(car U, V))
  32. else XN(cdr U, V);
  33. lisp procedure XNQ(U, V); %. EQ version of XN
  34. if null PairP U then NIL
  35. else if car U memq V then car U . XN(cdr U, DelQ(car U, V))
  36. else XN(cdr U, V);
  37. LoadTime
  38. << PutD('Intersection, 'EXPR, cdr GetD 'XN); % for those who like to type
  39. PutD('IntersectionQ, 'EXPR, cdr GetD 'XNQ) >>;
  40. END;