annotate lisp/hyperbole/set.el @ 36:c53a95d3c46d r19-15b101

Import from CVS: tag r19-15b101
author cvs
date Mon, 13 Aug 2007 08:53:38 +0200
parents 376386a54a3c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;!emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; FILE: set.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; SUMMARY: Provide general mathematical operators on unordered sets.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; USAGE: GNU Emacs Lisp Library
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; KEYWORDS: extensions, tools
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; AUTHOR: Bob Weiner
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; ORG: Brown U.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; ORIG-DATE: 26-Sep-91 at 19:24:19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; LAST-MOD: 14-Apr-95 at 16:17:03 by Bob Weiner
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; This file is part of Hyperbole.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; Available for use and distribution under the same terms as GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; Copyright (C) 1991-1995, Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; Developed with support from Motorola Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; DESCRIPTION:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; All set operations herein work with sets of arbitrary Lisp objects,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;; including strings. By default, they use 'equal' for comparisons
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;; but this may be overidden by changing the function bound to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;; the 'set:equal-op' variable.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;; DESCRIP-END.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; Other required Elisp libraries
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;; Public variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 (defvar set:equal-op 'equal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 "Comparison function used by set operators.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 It must be a function of two arguments which returns non-nil only when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 the arguments are equivalent.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;; Public functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (defmacro set:add (elt set)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 "Adds element ELT to SET and then returns SET.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 Uses 'set:equal-op' for comparison.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 Use (setq set (set:add elt set)) to assure set is always properly modified."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (` (cond ((set:member (, elt) (, set)) (, set))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ((, set) (setq (, set) (cons (, elt) (, set))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (t (list (, elt))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (defun set:combinations (set &optional arity)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 "Returns all possible combinations (subsets) of SET.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 Assumes SET is a valid set. With optional ARITY, returns only subsets with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ARITY members."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (cond ((null arity)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (setq arity 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (cons nil (apply 'nconc (mapcar (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (lambda (elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (setq arity (1+ arity))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (set:combinations set arity)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 set))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 ((= arity 1) set)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ((<= arity 0) '(nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (t (let ((rest) (ctr 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (apply
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 'nconc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (mapcar (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (lambda (first)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (setq rest (nthcdr ctr set)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ctr (1+ ctr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (mapcar (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (lambda (elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (if (listp elt) (cons first elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (list first elt))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (set:combinations rest (1- arity)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 set))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (defun set:create (&rest elements)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 "Returns a new set created from any number of ELEMENTS or a list of ELEMENTS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 Uses 'set:equal-op' for comparison."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (let ((set))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (mapcar (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (lambda (elt) (or (set:member elt set)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (setq set (cons elt set)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (if (or (null (car elements)) (not (listp (car elements))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 elements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (car elements)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 set))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (fset 'set:delete 'set:remove)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (defun set:difference (&rest sets)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 "Returns difference of any number of SETS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 Difference is the set of elements in the first set that are not in any of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 other sets. Uses 'set:equal-op' for comparison."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (let ((rtn-set (set:members (car sets))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (lambda (set)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (mapcar (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (lambda (elt) (set:remove elt rtn-set)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 set)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (cdr sets))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 rtn-set))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (defun set:equal (set1 set2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 "Returns t iff SET1 contains the same members as SET2. Both must be sets.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 Uses 'set:equal-op' for comparison."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (and (listp set1) (listp set2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (= (set:size set1) (set:size set2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (set:subset set1 set2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (defun set:get (key set)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 "Returns the value associated with KEY in SET or nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 Elements of SET should be of the form (key . value)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (cdr (car (let ((set:equal-op
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (function (lambda (key elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (equal key (car elt))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (set:member key set)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (defun set:intersection (&rest sets)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 "Returns intersection of all SETS given as arguments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 Uses 'set:equal-op' for comparison."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (let ((rtn-set))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (lambda (elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (or (memq nil (mapcar (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (lambda (set) (set:member elt set)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (cdr sets)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (setq rtn-set (cons elt rtn-set)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (car sets))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 rtn-set))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (defun set:is (obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 "Returns t if OBJ is a set (a list with no repeated elements).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 Uses 'set:equal-op' for comparison."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (and (listp obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (let ((lst obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (while (and (not (set:member (car lst) (cdr lst)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (setq lst (cdr lst))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (null lst))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (fset 'set:map 'mapcar)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (defun set:member (elt set)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 "Returns non-nil if ELT is an element of SET.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 The value is actually the tail of SET whose car is ELT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 Uses 'set:equal-op' for comparison."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (while (and set (not (funcall set:equal-op elt (car set))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (setq set (cdr set)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 set)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (defun set:members (list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 "Returns set of unique elements of LIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 Uses 'set:equal-op' for comparison. See also 'set:create'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (let ((set))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (mapcar (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (lambda (elt) (or (set:member elt set) (setq set (cons elt set)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 set))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (defmacro set:remove (elt set)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 "Removes element ELT from SET and returns new set.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 Assumes SET is a valid set. Uses 'set:equal-op' for comparison.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 Use (setq set (set:remove elt set)) to assure set is always properly modified."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (` (let ((rest (set:member (, elt) (, set)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (rtn (, set)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (if rest
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (cond ((= (length rtn) 1) (setq rtn nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 ((= (length rest) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (setcdr (nthcdr (- (length rtn) 2) rtn) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (t (setcar rest (car (cdr rest)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (setcdr rest (cdr (cdr rest))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 rtn)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (defun set:replace (key value set)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 "Replaces or adds element whose car matches KEY with element (KEY . VALUE) in SET.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 Returns set if modified, else nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 Use (setq set (set:replace elt set)) to assure set is always properly modified.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 Uses 'set:equal-op' to match against KEY. Assumes each element in the set
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 has a car and a cdr."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (let ((elt-set (set:member key set)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (if elt-set
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 ;; replace element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (progn (setcar elt-set (cons key value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 set)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 ;; add new element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (cons (cons key value) set))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (fset 'set:size 'length)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (defun set:subset (sub set)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 "Returns t iff set SUB is a subset of SET.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 Uses 'set:equal-op' for comparison."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (let ((is t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (mapcar (function (lambda (elt) (if is (setq is (set:member elt set))))) sub)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (and is t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (defun set:union (&rest sets)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 "Returns union of all SETS given as arguments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 Uses 'set:equal-op' for comparison."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (let ((rtn-set))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (lambda (set) (mapcar (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (lambda (elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (setq rtn-set (set:add elt rtn-set))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 set)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 sets)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 rtn-set))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 ;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 ;; Private variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 ;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (provide 'set)