Mercurial > emacs
annotate lisp/emacs-lisp/cl-seq.el @ 108590:c84578d13e42
calc-aent.el (math-read-token, math-find-user-tokens):
calc-lang.el (math-read-big-rec, math-lang-read-symbol)
(math-compose-tex-func):
calccomp.el (math-compose-expr):
calc-ext.el (math-format-flat-expr-fancy):
calc-store.el (calc-read-var-name):
calc-units.el (calc-explain-units-rec): Allow Greek letters.
calc.el (var-¦Ð, var-¦Õ, var-¦Ã): New variables.
calc-aent.el (math-read-replacement-list): Add "micro" symbol.
calc-units.el (math-unit-prefixes): Add mu for micro.
(math-standard-units): Add units.
author | Jay Belanger <jay.p.belanger@gmail.com> |
---|---|
date | Fri, 14 May 2010 23:50:25 -0500 |
parents | 1d1d5d9bd884 |
children | 280c8ae2476d 376148b31b5e |
rev | line source |
---|---|
85726
370f231ade90
Unify local variable section, and set byte-compile-warnings to `(not
Glenn Morris <rgm@gnu.org>
parents:
82140
diff
changeset
|
1 ;;; cl-seq.el --- Common Lisp features, part 3 |
4355 | 2 |
96710
e3b70303f1e9
Simply require 'cl (silences spurious warnings).
Glenn Morris <rgm@gnu.org>
parents:
94655
diff
changeset
|
3 ;; Copyright (C) 1993, 2001, 2002, 2003, 2004, 2005, 2006, 2007, |
106815 | 4 ;; 2008, 2009, 2010 Free Software Foundation, Inc. |
4355 | 5 |
6 ;; Author: Dave Gillespie <daveg@synaptics.com> | |
7 ;; Version: 2.02 | |
8 ;; Keywords: extensions | |
9 | |
10 ;; This file is part of GNU Emacs. | |
11 | |
94655
90a2847062be
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
12 ;; GNU Emacs is free software: you can redistribute it and/or modify |
4355 | 13 ;; it under the terms of the GNU General Public License as published by |
94655
90a2847062be
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
14 ;; the Free Software Foundation, either version 3 of the License, or |
90a2847062be
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
15 ;; (at your option) any later version. |
4355 | 16 |
17 ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;; GNU General Public License for more details. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
94655
90a2847062be
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
4355 | 24 |
7942 | 25 ;;; Commentary: |
4355 | 26 |
27 ;; These are extensions to Emacs Lisp that provide a degree of | |
28 ;; Common Lisp compatibility, beyond what is already built-in | |
29 ;; in Emacs Lisp. | |
30 ;; | |
31 ;; This package was written by Dave Gillespie; it is a complete | |
32 ;; rewrite of Cesar Quiroz's original cl.el package of December 1986. | |
33 ;; | |
34 ;; Bug reports, comments, and suggestions are welcome! | |
35 | |
36 ;; This file contains the Common Lisp sequence and list functions | |
37 ;; which take keyword arguments. | |
38 | |
39 ;; See cl.el for Change Log. | |
40 | |
41 | |
7942 | 42 ;;; Code: |
4355 | 43 |
96710
e3b70303f1e9
Simply require 'cl (silences spurious warnings).
Glenn Morris <rgm@gnu.org>
parents:
94655
diff
changeset
|
44 (require 'cl) |
4355 | 45 |
46 ;;; Keyword parsing. This is special-cased here so that we can compile | |
47 ;;; this file independent from cl-macs. | |
48 | |
49 (defmacro cl-parsing-keywords (kwords other-keys &rest body) | |
50 (cons | |
51 'let* | |
52 (cons (mapcar | |
53 (function | |
54 (lambda (x) | |
55 (let* ((var (if (consp x) (car x) x)) | |
56 (mem (list 'car (list 'cdr (list 'memq (list 'quote var) | |
57 'cl-keys))))) | |
28824
add63b27c709
Doc fixes; mainly avoid duplicating arg
Dave Love <fx@gnu.org>
parents:
16057
diff
changeset
|
58 (if (eq var :test-not) |
4355 | 59 (setq mem (list 'and mem (list 'setq 'cl-test mem) t))) |
28824
add63b27c709
Doc fixes; mainly avoid duplicating arg
Dave Love <fx@gnu.org>
parents:
16057
diff
changeset
|
60 (if (eq var :if-not) |
4355 | 61 (setq mem (list 'and mem (list 'setq 'cl-if mem) t))) |
62 (list (intern | |
63 (format "cl-%s" (substring (symbol-name var) 1))) | |
64 (if (consp x) (list 'or mem (car (cdr x))) mem))))) | |
65 kwords) | |
66 (append | |
67 (and (not (eq other-keys t)) | |
68 (list | |
69 (list 'let '((cl-keys-temp cl-keys)) | |
70 (list 'while 'cl-keys-temp | |
71 (list 'or (list 'memq '(car cl-keys-temp) | |
72 (list 'quote | |
73 (mapcar | |
74 (function | |
75 (lambda (x) | |
76 (if (consp x) | |
77 (car x) x))) | |
78 (append kwords | |
79 other-keys)))) | |
80 '(car (cdr (memq (quote :allow-other-keys) | |
81 cl-keys))) | |
82 '(error "Bad keyword argument %s" | |
83 (car cl-keys-temp))) | |
84 '(setq cl-keys-temp (cdr (cdr cl-keys-temp))))))) | |
85 body)))) | |
86 (put 'cl-parsing-keywords 'lisp-indent-function 2) | |
87 (put 'cl-parsing-keywords 'edebug-form-spec '(sexp sexp &rest form)) | |
88 | |
89 (defmacro cl-check-key (x) | |
90 (list 'if 'cl-key (list 'funcall 'cl-key x) x)) | |
91 | |
92 (defmacro cl-check-test-nokey (item x) | |
93 (list 'cond | |
94 (list 'cl-test | |
95 (list 'eq (list 'not (list 'funcall 'cl-test item x)) | |
96 'cl-test-not)) | |
97 (list 'cl-if | |
98 (list 'eq (list 'not (list 'funcall 'cl-if x)) 'cl-if-not)) | |
99 (list 't (list 'if (list 'numberp item) | |
100 (list 'equal item x) (list 'eq item x))))) | |
101 | |
102 (defmacro cl-check-test (item x) | |
103 (list 'cl-check-test-nokey item (list 'cl-check-key x))) | |
104 | |
105 (defmacro cl-check-match (x y) | |
106 (setq x (list 'cl-check-key x) y (list 'cl-check-key y)) | |
107 (list 'if 'cl-test | |
108 (list 'eq (list 'not (list 'funcall 'cl-test x y)) 'cl-test-not) | |
109 (list 'if (list 'numberp x) | |
110 (list 'equal x y) (list 'eq x y)))) | |
111 | |
112 (put 'cl-check-key 'edebug-form-spec 'edebug-forms) | |
113 (put 'cl-check-test 'edebug-form-spec 'edebug-forms) | |
114 (put 'cl-check-test-nokey 'edebug-form-spec 'edebug-forms) | |
115 (put 'cl-check-match 'edebug-form-spec 'edebug-forms) | |
116 | |
117 (defvar cl-test) (defvar cl-test-not) | |
118 (defvar cl-if) (defvar cl-if-not) | |
119 (defvar cl-key) | |
120 | |
121 | |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
122 ;;;###autoload |
4355 | 123 (defun reduce (cl-func cl-seq &rest cl-keys) |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
124 "Reduce two-argument FUNCTION across SEQ. |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
125 \nKeywords supported: :start :end :from-end :initial-value :key |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
126 \n(fn FUNCTION SEQ [KEYWORD VALUE]...)" |
4355 | 127 (cl-parsing-keywords (:from-end (:start 0) :end :initial-value :key) () |
128 (or (listp cl-seq) (setq cl-seq (append cl-seq nil))) | |
129 (setq cl-seq (subseq cl-seq cl-start cl-end)) | |
130 (if cl-from-end (setq cl-seq (nreverse cl-seq))) | |
28824
add63b27c709
Doc fixes; mainly avoid duplicating arg
Dave Love <fx@gnu.org>
parents:
16057
diff
changeset
|
131 (let ((cl-accum (cond ((memq :initial-value cl-keys) cl-initial-value) |
47661
025c490d435b
(cl-push, cl-pop): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42964
diff
changeset
|
132 (cl-seq (cl-check-key (pop cl-seq))) |
4355 | 133 (t (funcall cl-func))))) |
134 (if cl-from-end | |
135 (while cl-seq | |
47661
025c490d435b
(cl-push, cl-pop): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42964
diff
changeset
|
136 (setq cl-accum (funcall cl-func (cl-check-key (pop cl-seq)) |
4355 | 137 cl-accum))) |
138 (while cl-seq | |
139 (setq cl-accum (funcall cl-func cl-accum | |
47661
025c490d435b
(cl-push, cl-pop): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42964
diff
changeset
|
140 (cl-check-key (pop cl-seq)))))) |
4355 | 141 cl-accum))) |
142 | |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
143 ;;;###autoload |
4355 | 144 (defun fill (seq item &rest cl-keys) |
145 "Fill the elements of SEQ with ITEM. | |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
146 \nKeywords supported: :start :end |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
147 \n(fn SEQ ITEM [KEYWORD VALUE]...)" |
4355 | 148 (cl-parsing-keywords ((:start 0) :end) () |
149 (if (listp seq) | |
150 (let ((p (nthcdr cl-start seq)) | |
151 (n (if cl-end (- cl-end cl-start) 8000000))) | |
152 (while (and p (>= (setq n (1- n)) 0)) | |
153 (setcar p item) | |
154 (setq p (cdr p)))) | |
155 (or cl-end (setq cl-end (length seq))) | |
156 (if (and (= cl-start 0) (= cl-end (length seq))) | |
157 (fillarray seq item) | |
158 (while (< cl-start cl-end) | |
159 (aset seq cl-start item) | |
160 (setq cl-start (1+ cl-start))))) | |
161 seq)) | |
162 | |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
163 ;;;###autoload |
4355 | 164 (defun replace (cl-seq1 cl-seq2 &rest cl-keys) |
165 "Replace the elements of SEQ1 with the elements of SEQ2. | |
166 SEQ1 is destructively modified, then returned. | |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
167 \nKeywords supported: :start1 :end1 :start2 :end2 |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
168 \n(fn SEQ1 SEQ2 [KEYWORD VALUE]...)" |
4355 | 169 (cl-parsing-keywords ((:start1 0) :end1 (:start2 0) :end2) () |
170 (if (and (eq cl-seq1 cl-seq2) (<= cl-start2 cl-start1)) | |
171 (or (= cl-start1 cl-start2) | |
172 (let* ((cl-len (length cl-seq1)) | |
173 (cl-n (min (- (or cl-end1 cl-len) cl-start1) | |
174 (- (or cl-end2 cl-len) cl-start2)))) | |
175 (while (>= (setq cl-n (1- cl-n)) 0) | |
176 (cl-set-elt cl-seq1 (+ cl-start1 cl-n) | |
177 (elt cl-seq2 (+ cl-start2 cl-n)))))) | |
178 (if (listp cl-seq1) | |
179 (let ((cl-p1 (nthcdr cl-start1 cl-seq1)) | |
180 (cl-n1 (if cl-end1 (- cl-end1 cl-start1) 4000000))) | |
181 (if (listp cl-seq2) | |
182 (let ((cl-p2 (nthcdr cl-start2 cl-seq2)) | |
183 (cl-n (min cl-n1 | |
184 (if cl-end2 (- cl-end2 cl-start2) 4000000)))) | |
185 (while (and cl-p1 cl-p2 (>= (setq cl-n (1- cl-n)) 0)) | |
186 (setcar cl-p1 (car cl-p2)) | |
187 (setq cl-p1 (cdr cl-p1) cl-p2 (cdr cl-p2)))) | |
188 (setq cl-end2 (min (or cl-end2 (length cl-seq2)) | |
189 (+ cl-start2 cl-n1))) | |
190 (while (and cl-p1 (< cl-start2 cl-end2)) | |
191 (setcar cl-p1 (aref cl-seq2 cl-start2)) | |
192 (setq cl-p1 (cdr cl-p1) cl-start2 (1+ cl-start2))))) | |
193 (setq cl-end1 (min (or cl-end1 (length cl-seq1)) | |
194 (+ cl-start1 (- (or cl-end2 (length cl-seq2)) | |
195 cl-start2)))) | |
196 (if (listp cl-seq2) | |
197 (let ((cl-p2 (nthcdr cl-start2 cl-seq2))) | |
198 (while (< cl-start1 cl-end1) | |
199 (aset cl-seq1 cl-start1 (car cl-p2)) | |
200 (setq cl-p2 (cdr cl-p2) cl-start1 (1+ cl-start1)))) | |
201 (while (< cl-start1 cl-end1) | |
202 (aset cl-seq1 cl-start1 (aref cl-seq2 cl-start2)) | |
203 (setq cl-start2 (1+ cl-start2) cl-start1 (1+ cl-start1)))))) | |
204 cl-seq1)) | |
205 | |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
206 ;;;###autoload |
4355 | 207 (defun remove* (cl-item cl-seq &rest cl-keys) |
208 "Remove all occurrences of ITEM in SEQ. | |
209 This is a non-destructive function; it makes a copy of SEQ if necessary | |
210 to avoid corrupting the original SEQ. | |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
211 \nKeywords supported: :test :test-not :key :count :start :end :from-end |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
212 \n(fn ITEM SEQ [KEYWORD VALUE]...)" |
4355 | 213 (cl-parsing-keywords (:test :test-not :key :if :if-not :count :from-end |
214 (:start 0) :end) () | |
215 (if (<= (or cl-count (setq cl-count 8000000)) 0) | |
216 cl-seq | |
217 (if (or (nlistp cl-seq) (and cl-from-end (< cl-count 4000000))) | |
218 (let ((cl-i (cl-position cl-item cl-seq cl-start cl-end | |
219 cl-from-end))) | |
220 (if cl-i | |
221 (let ((cl-res (apply 'delete* cl-item (append cl-seq nil) | |
222 (append (if cl-from-end | |
28824
add63b27c709
Doc fixes; mainly avoid duplicating arg
Dave Love <fx@gnu.org>
parents:
16057
diff
changeset
|
223 (list :end (1+ cl-i)) |
add63b27c709
Doc fixes; mainly avoid duplicating arg
Dave Love <fx@gnu.org>
parents:
16057
diff
changeset
|
224 (list :start cl-i)) |
4355 | 225 cl-keys)))) |
226 (if (listp cl-seq) cl-res | |
227 (if (stringp cl-seq) (concat cl-res) (vconcat cl-res)))) | |
228 cl-seq)) | |
229 (setq cl-end (- (or cl-end 8000000) cl-start)) | |
230 (if (= cl-start 0) | |
231 (while (and cl-seq (> cl-end 0) | |
232 (cl-check-test cl-item (car cl-seq)) | |
233 (setq cl-end (1- cl-end) cl-seq (cdr cl-seq)) | |
234 (> (setq cl-count (1- cl-count)) 0)))) | |
235 (if (and (> cl-count 0) (> cl-end 0)) | |
236 (let ((cl-p (if (> cl-start 0) (nthcdr cl-start cl-seq) | |
237 (setq cl-end (1- cl-end)) (cdr cl-seq)))) | |
238 (while (and cl-p (> cl-end 0) | |
239 (not (cl-check-test cl-item (car cl-p)))) | |
240 (setq cl-p (cdr cl-p) cl-end (1- cl-end))) | |
241 (if (and cl-p (> cl-end 0)) | |
242 (nconc (ldiff cl-seq cl-p) | |
243 (if (= cl-count 1) (cdr cl-p) | |
244 (and (cdr cl-p) | |
245 (apply 'delete* cl-item | |
246 (copy-sequence (cdr cl-p)) | |
28824
add63b27c709
Doc fixes; mainly avoid duplicating arg
Dave Love <fx@gnu.org>
parents:
16057
diff
changeset
|
247 :start 0 :end (1- cl-end) |
add63b27c709
Doc fixes; mainly avoid duplicating arg
Dave Love <fx@gnu.org>
parents:
16057
diff
changeset
|
248 :count (1- cl-count) cl-keys)))) |
4355 | 249 cl-seq)) |
250 cl-seq))))) | |
251 | |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
252 ;;;###autoload |
4355 | 253 (defun remove-if (cl-pred cl-list &rest cl-keys) |
254 "Remove all items satisfying PREDICATE in SEQ. | |
255 This is a non-destructive function; it makes a copy of SEQ if necessary | |
256 to avoid corrupting the original SEQ. | |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
257 \nKeywords supported: :key :count :start :end :from-end |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
258 \n(fn PREDICATE SEQ [KEYWORD VALUE]...)" |
28824
add63b27c709
Doc fixes; mainly avoid duplicating arg
Dave Love <fx@gnu.org>
parents:
16057
diff
changeset
|
259 (apply 'remove* nil cl-list :if cl-pred cl-keys)) |
4355 | 260 |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
261 ;;;###autoload |
4355 | 262 (defun remove-if-not (cl-pred cl-list &rest cl-keys) |
263 "Remove all items not satisfying PREDICATE in SEQ. | |
264 This is a non-destructive function; it makes a copy of SEQ if necessary | |
265 to avoid corrupting the original SEQ. | |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
266 \nKeywords supported: :key :count :start :end :from-end |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
267 \n(fn PREDICATE SEQ [KEYWORD VALUE]...)" |
28824
add63b27c709
Doc fixes; mainly avoid duplicating arg
Dave Love <fx@gnu.org>
parents:
16057
diff
changeset
|
268 (apply 'remove* nil cl-list :if-not cl-pred cl-keys)) |
4355 | 269 |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
270 ;;;###autoload |
4355 | 271 (defun delete* (cl-item cl-seq &rest cl-keys) |
272 "Remove all occurrences of ITEM in SEQ. | |
273 This is a destructive function; it reuses the storage of SEQ whenever possible. | |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
274 \nKeywords supported: :test :test-not :key :count :start :end :from-end |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
275 \n(fn ITEM SEQ [KEYWORD VALUE]...)" |
4355 | 276 (cl-parsing-keywords (:test :test-not :key :if :if-not :count :from-end |
277 (:start 0) :end) () | |
278 (if (<= (or cl-count (setq cl-count 8000000)) 0) | |
279 cl-seq | |
280 (if (listp cl-seq) | |
281 (if (and cl-from-end (< cl-count 4000000)) | |
282 (let (cl-i) | |
283 (while (and (>= (setq cl-count (1- cl-count)) 0) | |
284 (setq cl-i (cl-position cl-item cl-seq cl-start | |
285 cl-end cl-from-end))) | |
286 (if (= cl-i 0) (setq cl-seq (cdr cl-seq)) | |
287 (let ((cl-tail (nthcdr (1- cl-i) cl-seq))) | |
288 (setcdr cl-tail (cdr (cdr cl-tail))))) | |
289 (setq cl-end cl-i)) | |
290 cl-seq) | |
291 (setq cl-end (- (or cl-end 8000000) cl-start)) | |
292 (if (= cl-start 0) | |
293 (progn | |
294 (while (and cl-seq | |
295 (> cl-end 0) | |
296 (cl-check-test cl-item (car cl-seq)) | |
297 (setq cl-end (1- cl-end) cl-seq (cdr cl-seq)) | |
298 (> (setq cl-count (1- cl-count)) 0))) | |
299 (setq cl-end (1- cl-end))) | |
300 (setq cl-start (1- cl-start))) | |
301 (if (and (> cl-count 0) (> cl-end 0)) | |
302 (let ((cl-p (nthcdr cl-start cl-seq))) | |
303 (while (and (cdr cl-p) (> cl-end 0)) | |
304 (if (cl-check-test cl-item (car (cdr cl-p))) | |
305 (progn | |
306 (setcdr cl-p (cdr (cdr cl-p))) | |
307 (if (= (setq cl-count (1- cl-count)) 0) | |
308 (setq cl-end 1))) | |
309 (setq cl-p (cdr cl-p))) | |
310 (setq cl-end (1- cl-end))))) | |
311 cl-seq) | |
312 (apply 'remove* cl-item cl-seq cl-keys))))) | |
313 | |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
314 ;;;###autoload |
4355 | 315 (defun delete-if (cl-pred cl-list &rest cl-keys) |
316 "Remove all items satisfying PREDICATE in SEQ. | |
317 This is a destructive function; it reuses the storage of SEQ whenever possible. | |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
318 \nKeywords supported: :key :count :start :end :from-end |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
319 \n(fn PREDICATE SEQ [KEYWORD VALUE]...)" |
28824
add63b27c709
Doc fixes; mainly avoid duplicating arg
Dave Love <fx@gnu.org>
parents:
16057
diff
changeset
|
320 (apply 'delete* nil cl-list :if cl-pred cl-keys)) |
4355 | 321 |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
322 ;;;###autoload |
4355 | 323 (defun delete-if-not (cl-pred cl-list &rest cl-keys) |
324 "Remove all items not satisfying PREDICATE in SEQ. | |
325 This is a destructive function; it reuses the storage of SEQ whenever possible. | |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
326 \nKeywords supported: :key :count :start :end :from-end |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
327 \n(fn PREDICATE SEQ [KEYWORD VALUE]...)" |
28824
add63b27c709
Doc fixes; mainly avoid duplicating arg
Dave Love <fx@gnu.org>
parents:
16057
diff
changeset
|
328 (apply 'delete* nil cl-list :if-not cl-pred cl-keys)) |
4355 | 329 |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
330 ;;;###autoload |
4355 | 331 (defun remove-duplicates (cl-seq &rest cl-keys) |
332 "Return a copy of SEQ with all duplicate elements removed. | |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
333 \nKeywords supported: :test :test-not :key :start :end :from-end |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
334 \n(fn SEQ [KEYWORD VALUE]...)" |
4355 | 335 (cl-delete-duplicates cl-seq cl-keys t)) |
336 | |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
337 ;;;###autoload |
4355 | 338 (defun delete-duplicates (cl-seq &rest cl-keys) |
339 "Remove all duplicate elements from SEQ (destructively). | |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
340 \nKeywords supported: :test :test-not :key :start :end :from-end |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
341 \n(fn SEQ [KEYWORD VALUE]...)" |
4355 | 342 (cl-delete-duplicates cl-seq cl-keys nil)) |
343 | |
344 (defun cl-delete-duplicates (cl-seq cl-keys cl-copy) | |
345 (if (listp cl-seq) | |
346 (cl-parsing-keywords (:test :test-not :key (:start 0) :end :from-end :if) | |
347 () | |
348 (if cl-from-end | |
349 (let ((cl-p (nthcdr cl-start cl-seq)) cl-i) | |
350 (setq cl-end (- (or cl-end (length cl-seq)) cl-start)) | |
351 (while (> cl-end 1) | |
352 (setq cl-i 0) | |
353 (while (setq cl-i (cl-position (cl-check-key (car cl-p)) | |
354 (cdr cl-p) cl-i (1- cl-end))) | |
355 (if cl-copy (setq cl-seq (copy-sequence cl-seq) | |
356 cl-p (nthcdr cl-start cl-seq) cl-copy nil)) | |
357 (let ((cl-tail (nthcdr cl-i cl-p))) | |
358 (setcdr cl-tail (cdr (cdr cl-tail)))) | |
359 (setq cl-end (1- cl-end))) | |
360 (setq cl-p (cdr cl-p) cl-end (1- cl-end) | |
361 cl-start (1+ cl-start))) | |
362 cl-seq) | |
363 (setq cl-end (- (or cl-end (length cl-seq)) cl-start)) | |
364 (while (and (cdr cl-seq) (= cl-start 0) (> cl-end 1) | |
365 (cl-position (cl-check-key (car cl-seq)) | |
366 (cdr cl-seq) 0 (1- cl-end))) | |
367 (setq cl-seq (cdr cl-seq) cl-end (1- cl-end))) | |
368 (let ((cl-p (if (> cl-start 0) (nthcdr (1- cl-start) cl-seq) | |
369 (setq cl-end (1- cl-end) cl-start 1) cl-seq))) | |
370 (while (and (cdr (cdr cl-p)) (> cl-end 1)) | |
371 (if (cl-position (cl-check-key (car (cdr cl-p))) | |
372 (cdr (cdr cl-p)) 0 (1- cl-end)) | |
373 (progn | |
374 (if cl-copy (setq cl-seq (copy-sequence cl-seq) | |
375 cl-p (nthcdr (1- cl-start) cl-seq) | |
376 cl-copy nil)) | |
377 (setcdr cl-p (cdr (cdr cl-p)))) | |
378 (setq cl-p (cdr cl-p))) | |
379 (setq cl-end (1- cl-end) cl-start (1+ cl-start))) | |
380 cl-seq))) | |
381 (let ((cl-res (cl-delete-duplicates (append cl-seq nil) cl-keys nil))) | |
382 (if (stringp cl-seq) (concat cl-res) (vconcat cl-res))))) | |
383 | |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
384 ;;;###autoload |
4355 | 385 (defun substitute (cl-new cl-old cl-seq &rest cl-keys) |
386 "Substitute NEW for OLD in SEQ. | |
387 This is a non-destructive function; it makes a copy of SEQ if necessary | |
388 to avoid corrupting the original SEQ. | |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
389 \nKeywords supported: :test :test-not :key :count :start :end :from-end |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
390 \n(fn NEW OLD SEQ [KEYWORD VALUE]...)" |
4355 | 391 (cl-parsing-keywords (:test :test-not :key :if :if-not :count |
392 (:start 0) :end :from-end) () | |
393 (if (or (eq cl-old cl-new) | |
394 (<= (or cl-count (setq cl-from-end nil cl-count 8000000)) 0)) | |
395 cl-seq | |
396 (let ((cl-i (cl-position cl-old cl-seq cl-start cl-end))) | |
397 (if (not cl-i) | |
398 cl-seq | |
399 (setq cl-seq (copy-sequence cl-seq)) | |
400 (or cl-from-end | |
401 (progn (cl-set-elt cl-seq cl-i cl-new) | |
402 (setq cl-i (1+ cl-i) cl-count (1- cl-count)))) | |
28824
add63b27c709
Doc fixes; mainly avoid duplicating arg
Dave Love <fx@gnu.org>
parents:
16057
diff
changeset
|
403 (apply 'nsubstitute cl-new cl-old cl-seq :count cl-count |
add63b27c709
Doc fixes; mainly avoid duplicating arg
Dave Love <fx@gnu.org>
parents:
16057
diff
changeset
|
404 :start cl-i cl-keys)))))) |
4355 | 405 |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
406 ;;;###autoload |
4355 | 407 (defun substitute-if (cl-new cl-pred cl-list &rest cl-keys) |
408 "Substitute NEW for all items satisfying PREDICATE in SEQ. | |
409 This is a non-destructive function; it makes a copy of SEQ if necessary | |
410 to avoid corrupting the original SEQ. | |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
411 \nKeywords supported: :key :count :start :end :from-end |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
412 \n(fn NEW PREDICATE SEQ [KEYWORD VALUE]...)" |
28824
add63b27c709
Doc fixes; mainly avoid duplicating arg
Dave Love <fx@gnu.org>
parents:
16057
diff
changeset
|
413 (apply 'substitute cl-new nil cl-list :if cl-pred cl-keys)) |
4355 | 414 |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
415 ;;;###autoload |
4355 | 416 (defun substitute-if-not (cl-new cl-pred cl-list &rest cl-keys) |
417 "Substitute NEW for all items not satisfying PREDICATE in SEQ. | |
418 This is a non-destructive function; it makes a copy of SEQ if necessary | |
419 to avoid corrupting the original SEQ. | |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
420 \nKeywords supported: :key :count :start :end :from-end |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
421 \n(fn NEW PREDICATE SEQ [KEYWORD VALUE]...)" |
28824
add63b27c709
Doc fixes; mainly avoid duplicating arg
Dave Love <fx@gnu.org>
parents:
16057
diff
changeset
|
422 (apply 'substitute cl-new nil cl-list :if-not cl-pred cl-keys)) |
4355 | 423 |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
424 ;;;###autoload |
4355 | 425 (defun nsubstitute (cl-new cl-old cl-seq &rest cl-keys) |
426 "Substitute NEW for OLD in SEQ. | |
427 This is a destructive function; it reuses the storage of SEQ whenever possible. | |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
428 \nKeywords supported: :test :test-not :key :count :start :end :from-end |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
429 \n(fn NEW OLD SEQ [KEYWORD VALUE]...)" |
4355 | 430 (cl-parsing-keywords (:test :test-not :key :if :if-not :count |
431 (:start 0) :end :from-end) () | |
432 (or (eq cl-old cl-new) (<= (or cl-count (setq cl-count 8000000)) 0) | |
433 (if (and (listp cl-seq) (or (not cl-from-end) (> cl-count 4000000))) | |
434 (let ((cl-p (nthcdr cl-start cl-seq))) | |
435 (setq cl-end (- (or cl-end 8000000) cl-start)) | |
436 (while (and cl-p (> cl-end 0) (> cl-count 0)) | |
437 (if (cl-check-test cl-old (car cl-p)) | |
438 (progn | |
439 (setcar cl-p cl-new) | |
440 (setq cl-count (1- cl-count)))) | |
441 (setq cl-p (cdr cl-p) cl-end (1- cl-end)))) | |
442 (or cl-end (setq cl-end (length cl-seq))) | |
443 (if cl-from-end | |
444 (while (and (< cl-start cl-end) (> cl-count 0)) | |
445 (setq cl-end (1- cl-end)) | |
446 (if (cl-check-test cl-old (elt cl-seq cl-end)) | |
447 (progn | |
448 (cl-set-elt cl-seq cl-end cl-new) | |
449 (setq cl-count (1- cl-count))))) | |
450 (while (and (< cl-start cl-end) (> cl-count 0)) | |
451 (if (cl-check-test cl-old (aref cl-seq cl-start)) | |
452 (progn | |
453 (aset cl-seq cl-start cl-new) | |
454 (setq cl-count (1- cl-count)))) | |
455 (setq cl-start (1+ cl-start)))))) | |
456 cl-seq)) | |
457 | |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
458 ;;;###autoload |
4355 | 459 (defun nsubstitute-if (cl-new cl-pred cl-list &rest cl-keys) |
460 "Substitute NEW for all items satisfying PREDICATE in SEQ. | |
461 This is a destructive function; it reuses the storage of SEQ whenever possible. | |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
462 \nKeywords supported: :key :count :start :end :from-end |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
463 \n(fn NEW PREDICATE SEQ [KEYWORD VALUE]...)" |
28824
add63b27c709
Doc fixes; mainly avoid duplicating arg
Dave Love <fx@gnu.org>
parents:
16057
diff
changeset
|
464 (apply 'nsubstitute cl-new nil cl-list :if cl-pred cl-keys)) |
4355 | 465 |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
466 ;;;###autoload |
4355 | 467 (defun nsubstitute-if-not (cl-new cl-pred cl-list &rest cl-keys) |
468 "Substitute NEW for all items not satisfying PREDICATE in SEQ. | |
469 This is a destructive function; it reuses the storage of SEQ whenever possible. | |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
470 \nKeywords supported: :key :count :start :end :from-end |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
471 \n(fn NEW PREDICATE SEQ [KEYWORD VALUE]...)" |
28824
add63b27c709
Doc fixes; mainly avoid duplicating arg
Dave Love <fx@gnu.org>
parents:
16057
diff
changeset
|
472 (apply 'nsubstitute cl-new nil cl-list :if-not cl-pred cl-keys)) |
4355 | 473 |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
474 ;;;###autoload |
4355 | 475 (defun find (cl-item cl-seq &rest cl-keys) |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
476 "Find the first occurrence of ITEM in SEQ. |
4355 | 477 Return the matching ITEM, or nil if not found. |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
478 \nKeywords supported: :test :test-not :key :start :end :from-end |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
479 \n(fn ITEM SEQ [KEYWORD VALUE]...)" |
4355 | 480 (let ((cl-pos (apply 'position cl-item cl-seq cl-keys))) |
481 (and cl-pos (elt cl-seq cl-pos)))) | |
482 | |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
483 ;;;###autoload |
4355 | 484 (defun find-if (cl-pred cl-list &rest cl-keys) |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
485 "Find the first item satisfying PREDICATE in SEQ. |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
486 Return the matching item, or nil if not found. |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
487 \nKeywords supported: :key :start :end :from-end |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
488 \n(fn PREDICATE SEQ [KEYWORD VALUE]...)" |
28824
add63b27c709
Doc fixes; mainly avoid duplicating arg
Dave Love <fx@gnu.org>
parents:
16057
diff
changeset
|
489 (apply 'find nil cl-list :if cl-pred cl-keys)) |
4355 | 490 |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
491 ;;;###autoload |
4355 | 492 (defun find-if-not (cl-pred cl-list &rest cl-keys) |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
493 "Find the first item not satisfying PREDICATE in SEQ. |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
494 Return the matching item, or nil if not found. |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
495 \nKeywords supported: :key :start :end :from-end |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
496 \n(fn PREDICATE SEQ [KEYWORD VALUE]...)" |
28824
add63b27c709
Doc fixes; mainly avoid duplicating arg
Dave Love <fx@gnu.org>
parents:
16057
diff
changeset
|
497 (apply 'find nil cl-list :if-not cl-pred cl-keys)) |
4355 | 498 |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
499 ;;;###autoload |
4355 | 500 (defun position (cl-item cl-seq &rest cl-keys) |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
501 "Find the first occurrence of ITEM in SEQ. |
4355 | 502 Return the index of the matching item, or nil if not found. |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
503 \nKeywords supported: :test :test-not :key :start :end :from-end |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
504 \n(fn ITEM SEQ [KEYWORD VALUE]...)" |
4355 | 505 (cl-parsing-keywords (:test :test-not :key :if :if-not |
506 (:start 0) :end :from-end) () | |
507 (cl-position cl-item cl-seq cl-start cl-end cl-from-end))) | |
508 | |
509 (defun cl-position (cl-item cl-seq cl-start &optional cl-end cl-from-end) | |
510 (if (listp cl-seq) | |
511 (let ((cl-p (nthcdr cl-start cl-seq))) | |
512 (or cl-end (setq cl-end 8000000)) | |
513 (let ((cl-res nil)) | |
514 (while (and cl-p (< cl-start cl-end) (or (not cl-res) cl-from-end)) | |
515 (if (cl-check-test cl-item (car cl-p)) | |
516 (setq cl-res cl-start)) | |
517 (setq cl-p (cdr cl-p) cl-start (1+ cl-start))) | |
518 cl-res)) | |
519 (or cl-end (setq cl-end (length cl-seq))) | |
520 (if cl-from-end | |
521 (progn | |
522 (while (and (>= (setq cl-end (1- cl-end)) cl-start) | |
523 (not (cl-check-test cl-item (aref cl-seq cl-end))))) | |
524 (and (>= cl-end cl-start) cl-end)) | |
525 (while (and (< cl-start cl-end) | |
526 (not (cl-check-test cl-item (aref cl-seq cl-start)))) | |
527 (setq cl-start (1+ cl-start))) | |
528 (and (< cl-start cl-end) cl-start)))) | |
529 | |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
530 ;;;###autoload |
4355 | 531 (defun position-if (cl-pred cl-list &rest cl-keys) |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
532 "Find the first item satisfying PREDICATE in SEQ. |
4355 | 533 Return the index of the matching item, or nil if not found. |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
534 \nKeywords supported: :key :start :end :from-end |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
535 \n(fn PREDICATE SEQ [KEYWORD VALUE]...)" |
28824
add63b27c709
Doc fixes; mainly avoid duplicating arg
Dave Love <fx@gnu.org>
parents:
16057
diff
changeset
|
536 (apply 'position nil cl-list :if cl-pred cl-keys)) |
4355 | 537 |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
538 ;;;###autoload |
4355 | 539 (defun position-if-not (cl-pred cl-list &rest cl-keys) |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
540 "Find the first item not satisfying PREDICATE in SEQ. |
4355 | 541 Return the index of the matching item, or nil if not found. |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
542 \nKeywords supported: :key :start :end :from-end |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
543 \n(fn PREDICATE SEQ [KEYWORD VALUE]...)" |
28824
add63b27c709
Doc fixes; mainly avoid duplicating arg
Dave Love <fx@gnu.org>
parents:
16057
diff
changeset
|
544 (apply 'position nil cl-list :if-not cl-pred cl-keys)) |
4355 | 545 |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
546 ;;;###autoload |
4355 | 547 (defun count (cl-item cl-seq &rest cl-keys) |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
548 "Count the number of occurrences of ITEM in SEQ. |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
549 \nKeywords supported: :test :test-not :key :start :end |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
550 \n(fn ITEM SEQ [KEYWORD VALUE]...)" |
4355 | 551 (cl-parsing-keywords (:test :test-not :key :if :if-not (:start 0) :end) () |
552 (let ((cl-count 0) cl-x) | |
553 (or cl-end (setq cl-end (length cl-seq))) | |
554 (if (consp cl-seq) (setq cl-seq (nthcdr cl-start cl-seq))) | |
555 (while (< cl-start cl-end) | |
47661
025c490d435b
(cl-push, cl-pop): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42964
diff
changeset
|
556 (setq cl-x (if (consp cl-seq) (pop cl-seq) (aref cl-seq cl-start))) |
4355 | 557 (if (cl-check-test cl-item cl-x) (setq cl-count (1+ cl-count))) |
558 (setq cl-start (1+ cl-start))) | |
559 cl-count))) | |
560 | |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
561 ;;;###autoload |
4355 | 562 (defun count-if (cl-pred cl-list &rest cl-keys) |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
563 "Count the number of items satisfying PREDICATE in SEQ. |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
564 \nKeywords supported: :key :start :end |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
565 \n(fn PREDICATE SEQ [KEYWORD VALUE]...)" |
28824
add63b27c709
Doc fixes; mainly avoid duplicating arg
Dave Love <fx@gnu.org>
parents:
16057
diff
changeset
|
566 (apply 'count nil cl-list :if cl-pred cl-keys)) |
4355 | 567 |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
568 ;;;###autoload |
4355 | 569 (defun count-if-not (cl-pred cl-list &rest cl-keys) |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
570 "Count the number of items not satisfying PREDICATE in SEQ. |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
571 \nKeywords supported: :key :start :end |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
572 \n(fn PREDICATE SEQ [KEYWORD VALUE]...)" |
28824
add63b27c709
Doc fixes; mainly avoid duplicating arg
Dave Love <fx@gnu.org>
parents:
16057
diff
changeset
|
573 (apply 'count nil cl-list :if-not cl-pred cl-keys)) |
4355 | 574 |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
575 ;;;###autoload |
4355 | 576 (defun mismatch (cl-seq1 cl-seq2 &rest cl-keys) |
577 "Compare SEQ1 with SEQ2, return index of first mismatching element. | |
578 Return nil if the sequences match. If one sequence is a prefix of the | |
42964 | 579 other, the return value indicates the end of the shorter sequence. |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
580 \nKeywords supported: :test :test-not :key :start1 :end1 :start2 :end2 :from-end |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
581 \n(fn SEQ1 SEQ2 [KEYWORD VALUE]...)" |
4355 | 582 (cl-parsing-keywords (:test :test-not :key :from-end |
583 (:start1 0) :end1 (:start2 0) :end2) () | |
584 (or cl-end1 (setq cl-end1 (length cl-seq1))) | |
585 (or cl-end2 (setq cl-end2 (length cl-seq2))) | |
586 (if cl-from-end | |
587 (progn | |
588 (while (and (< cl-start1 cl-end1) (< cl-start2 cl-end2) | |
589 (cl-check-match (elt cl-seq1 (1- cl-end1)) | |
590 (elt cl-seq2 (1- cl-end2)))) | |
591 (setq cl-end1 (1- cl-end1) cl-end2 (1- cl-end2))) | |
592 (and (or (< cl-start1 cl-end1) (< cl-start2 cl-end2)) | |
593 (1- cl-end1))) | |
594 (let ((cl-p1 (and (listp cl-seq1) (nthcdr cl-start1 cl-seq1))) | |
595 (cl-p2 (and (listp cl-seq2) (nthcdr cl-start2 cl-seq2)))) | |
596 (while (and (< cl-start1 cl-end1) (< cl-start2 cl-end2) | |
597 (cl-check-match (if cl-p1 (car cl-p1) | |
598 (aref cl-seq1 cl-start1)) | |
599 (if cl-p2 (car cl-p2) | |
600 (aref cl-seq2 cl-start2)))) | |
601 (setq cl-p1 (cdr cl-p1) cl-p2 (cdr cl-p2) | |
602 cl-start1 (1+ cl-start1) cl-start2 (1+ cl-start2))) | |
603 (and (or (< cl-start1 cl-end1) (< cl-start2 cl-end2)) | |
604 cl-start1))))) | |
605 | |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
606 ;;;###autoload |
4355 | 607 (defun search (cl-seq1 cl-seq2 &rest cl-keys) |
608 "Search for SEQ1 as a subsequence of SEQ2. | |
609 Return the index of the leftmost element of the first match found; | |
610 return nil if there are no matches. | |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
611 \nKeywords supported: :test :test-not :key :start1 :end1 :start2 :end2 :from-end |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
612 \n(fn SEQ1 SEQ2 [KEYWORD VALUE]...)" |
4355 | 613 (cl-parsing-keywords (:test :test-not :key :from-end |
614 (:start1 0) :end1 (:start2 0) :end2) () | |
615 (or cl-end1 (setq cl-end1 (length cl-seq1))) | |
616 (or cl-end2 (setq cl-end2 (length cl-seq2))) | |
617 (if (>= cl-start1 cl-end1) | |
618 (if cl-from-end cl-end2 cl-start2) | |
619 (let* ((cl-len (- cl-end1 cl-start1)) | |
620 (cl-first (cl-check-key (elt cl-seq1 cl-start1))) | |
621 (cl-if nil) cl-pos) | |
622 (setq cl-end2 (- cl-end2 (1- cl-len))) | |
623 (while (and (< cl-start2 cl-end2) | |
624 (setq cl-pos (cl-position cl-first cl-seq2 | |
625 cl-start2 cl-end2 cl-from-end)) | |
626 (apply 'mismatch cl-seq1 cl-seq2 | |
28824
add63b27c709
Doc fixes; mainly avoid duplicating arg
Dave Love <fx@gnu.org>
parents:
16057
diff
changeset
|
627 :start1 (1+ cl-start1) :end1 cl-end1 |
add63b27c709
Doc fixes; mainly avoid duplicating arg
Dave Love <fx@gnu.org>
parents:
16057
diff
changeset
|
628 :start2 (1+ cl-pos) :end2 (+ cl-pos cl-len) |
add63b27c709
Doc fixes; mainly avoid duplicating arg
Dave Love <fx@gnu.org>
parents:
16057
diff
changeset
|
629 :from-end nil cl-keys)) |
4355 | 630 (if cl-from-end (setq cl-end2 cl-pos) (setq cl-start2 (1+ cl-pos)))) |
631 (and (< cl-start2 cl-end2) cl-pos))))) | |
632 | |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
633 ;;;###autoload |
4355 | 634 (defun sort* (cl-seq cl-pred &rest cl-keys) |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
635 "Sort the argument SEQ according to PREDICATE. |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
636 This is a destructive function; it reuses the storage of SEQ if possible. |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
637 \nKeywords supported: :key |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
638 \n(fn SEQ PREDICATE [KEYWORD VALUE]...)" |
4355 | 639 (if (nlistp cl-seq) |
640 (replace cl-seq (apply 'sort* (append cl-seq nil) cl-pred cl-keys)) | |
641 (cl-parsing-keywords (:key) () | |
642 (if (memq cl-key '(nil identity)) | |
643 (sort cl-seq cl-pred) | |
644 (sort cl-seq (function (lambda (cl-x cl-y) | |
645 (funcall cl-pred (funcall cl-key cl-x) | |
646 (funcall cl-key cl-y))))))))) | |
647 | |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
648 ;;;###autoload |
4355 | 649 (defun stable-sort (cl-seq cl-pred &rest cl-keys) |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
650 "Sort the argument SEQ stably according to PREDICATE. |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
651 This is a destructive function; it reuses the storage of SEQ if possible. |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
652 \nKeywords supported: :key |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
653 \n(fn SEQ PREDICATE [KEYWORD VALUE]...)" |
4355 | 654 (apply 'sort* cl-seq cl-pred cl-keys)) |
655 | |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
656 ;;;###autoload |
4355 | 657 (defun merge (cl-type cl-seq1 cl-seq2 cl-pred &rest cl-keys) |
658 "Destructively merge the two sequences to produce a new sequence. | |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
659 TYPE is the sequence type to return, SEQ1 and SEQ2 are the two argument |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
660 sequences, and PREDICATE is a `less-than' predicate on the elements. |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
661 \nKeywords supported: :key |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
662 \n(fn TYPE SEQ1 SEQ2 PREDICATE [KEYWORD VALUE]...)" |
4355 | 663 (or (listp cl-seq1) (setq cl-seq1 (append cl-seq1 nil))) |
664 (or (listp cl-seq2) (setq cl-seq2 (append cl-seq2 nil))) | |
665 (cl-parsing-keywords (:key) () | |
666 (let ((cl-res nil)) | |
667 (while (and cl-seq1 cl-seq2) | |
668 (if (funcall cl-pred (cl-check-key (car cl-seq2)) | |
669 (cl-check-key (car cl-seq1))) | |
47661
025c490d435b
(cl-push, cl-pop): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42964
diff
changeset
|
670 (push (pop cl-seq2) cl-res) |
025c490d435b
(cl-push, cl-pop): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42964
diff
changeset
|
671 (push (pop cl-seq1) cl-res))) |
4355 | 672 (coerce (nconc (nreverse cl-res) cl-seq1 cl-seq2) cl-type)))) |
673 | |
674 ;;; See compiler macro in cl-macs.el | |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
675 ;;;###autoload |
4355 | 676 (defun member* (cl-item cl-list &rest cl-keys) |
677 "Find the first occurrence of ITEM in LIST. | |
678 Return the sublist of LIST whose car is ITEM. | |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
679 \nKeywords supported: :test :test-not :key |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
680 \n(fn ITEM LIST [KEYWORD VALUE]...)" |
4355 | 681 (if cl-keys |
682 (cl-parsing-keywords (:test :test-not :key :if :if-not) () | |
683 (while (and cl-list (not (cl-check-test cl-item (car cl-list)))) | |
684 (setq cl-list (cdr cl-list))) | |
685 cl-list) | |
686 (if (and (numberp cl-item) (not (integerp cl-item))) | |
687 (member cl-item cl-list) | |
688 (memq cl-item cl-list)))) | |
689 | |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
690 ;;;###autoload |
4355 | 691 (defun member-if (cl-pred cl-list &rest cl-keys) |
692 "Find the first item satisfying PREDICATE in LIST. | |
693 Return the sublist of LIST whose car matches. | |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
694 \nKeywords supported: :key |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
695 \n(fn PREDICATE LIST [KEYWORD VALUE]...)" |
28824
add63b27c709
Doc fixes; mainly avoid duplicating arg
Dave Love <fx@gnu.org>
parents:
16057
diff
changeset
|
696 (apply 'member* nil cl-list :if cl-pred cl-keys)) |
4355 | 697 |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
698 ;;;###autoload |
4355 | 699 (defun member-if-not (cl-pred cl-list &rest cl-keys) |
700 "Find the first item not satisfying PREDICATE in LIST. | |
701 Return the sublist of LIST whose car matches. | |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
702 \nKeywords supported: :key |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
703 \n(fn PREDICATE LIST [KEYWORD VALUE]...)" |
28824
add63b27c709
Doc fixes; mainly avoid duplicating arg
Dave Love <fx@gnu.org>
parents:
16057
diff
changeset
|
704 (apply 'member* nil cl-list :if-not cl-pred cl-keys)) |
4355 | 705 |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
706 ;;;###autoload |
4355 | 707 (defun cl-adjoin (cl-item cl-list &rest cl-keys) |
708 (if (cl-parsing-keywords (:key) t | |
709 (apply 'member* (cl-check-key cl-item) cl-list cl-keys)) | |
710 cl-list | |
711 (cons cl-item cl-list))) | |
712 | |
713 ;;; See compiler macro in cl-macs.el | |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
714 ;;;###autoload |
4355 | 715 (defun assoc* (cl-item cl-alist &rest cl-keys) |
716 "Find the first item whose car matches ITEM in LIST. | |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
717 \nKeywords supported: :test :test-not :key |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
718 \n(fn ITEM LIST [KEYWORD VALUE]...)" |
4355 | 719 (if cl-keys |
720 (cl-parsing-keywords (:test :test-not :key :if :if-not) () | |
721 (while (and cl-alist | |
722 (or (not (consp (car cl-alist))) | |
723 (not (cl-check-test cl-item (car (car cl-alist)))))) | |
724 (setq cl-alist (cdr cl-alist))) | |
725 (and cl-alist (car cl-alist))) | |
726 (if (and (numberp cl-item) (not (integerp cl-item))) | |
727 (assoc cl-item cl-alist) | |
728 (assq cl-item cl-alist)))) | |
729 | |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
730 ;;;###autoload |
4355 | 731 (defun assoc-if (cl-pred cl-list &rest cl-keys) |
732 "Find the first item whose car satisfies PREDICATE in LIST. | |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
733 \nKeywords supported: :key |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
734 \n(fn PREDICATE LIST [KEYWORD VALUE]...)" |
28824
add63b27c709
Doc fixes; mainly avoid duplicating arg
Dave Love <fx@gnu.org>
parents:
16057
diff
changeset
|
735 (apply 'assoc* nil cl-list :if cl-pred cl-keys)) |
4355 | 736 |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
737 ;;;###autoload |
4355 | 738 (defun assoc-if-not (cl-pred cl-list &rest cl-keys) |
739 "Find the first item whose car does not satisfy PREDICATE in LIST. | |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
740 \nKeywords supported: :key |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
741 \n(fn PREDICATE LIST [KEYWORD VALUE]...)" |
28824
add63b27c709
Doc fixes; mainly avoid duplicating arg
Dave Love <fx@gnu.org>
parents:
16057
diff
changeset
|
742 (apply 'assoc* nil cl-list :if-not cl-pred cl-keys)) |
4355 | 743 |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
744 ;;;###autoload |
4355 | 745 (defun rassoc* (cl-item cl-alist &rest cl-keys) |
746 "Find the first item whose cdr matches ITEM in LIST. | |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
747 \nKeywords supported: :test :test-not :key |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
748 \n(fn ITEM LIST [KEYWORD VALUE]...)" |
4355 | 749 (if (or cl-keys (numberp cl-item)) |
750 (cl-parsing-keywords (:test :test-not :key :if :if-not) () | |
751 (while (and cl-alist | |
752 (or (not (consp (car cl-alist))) | |
753 (not (cl-check-test cl-item (cdr (car cl-alist)))))) | |
754 (setq cl-alist (cdr cl-alist))) | |
755 (and cl-alist (car cl-alist))) | |
756 (rassq cl-item cl-alist))) | |
757 | |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
758 ;;;###autoload |
4355 | 759 (defun rassoc-if (cl-pred cl-list &rest cl-keys) |
760 "Find the first item whose cdr satisfies PREDICATE in LIST. | |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
761 \nKeywords supported: :key |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
762 \n(fn PREDICATE LIST [KEYWORD VALUE]...)" |
28824
add63b27c709
Doc fixes; mainly avoid duplicating arg
Dave Love <fx@gnu.org>
parents:
16057
diff
changeset
|
763 (apply 'rassoc* nil cl-list :if cl-pred cl-keys)) |
4355 | 764 |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
765 ;;;###autoload |
4355 | 766 (defun rassoc-if-not (cl-pred cl-list &rest cl-keys) |
767 "Find the first item whose cdr does not satisfy PREDICATE in LIST. | |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
768 \nKeywords supported: :key |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
769 \n(fn PREDICATE LIST [KEYWORD VALUE]...)" |
28824
add63b27c709
Doc fixes; mainly avoid duplicating arg
Dave Love <fx@gnu.org>
parents:
16057
diff
changeset
|
770 (apply 'rassoc* nil cl-list :if-not cl-pred cl-keys)) |
4355 | 771 |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
772 ;;;###autoload |
4355 | 773 (defun union (cl-list1 cl-list2 &rest cl-keys) |
774 "Combine LIST1 and LIST2 using a set-union operation. | |
775 The result list contains all items that appear in either LIST1 or LIST2. | |
776 This is a non-destructive function; it makes a copy of the data if necessary | |
777 to avoid corrupting the original LIST1 and LIST2. | |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
778 \nKeywords supported: :test :test-not :key |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
779 \n(fn LIST1 LIST2 [KEYWORD VALUE]...)" |
4355 | 780 (cond ((null cl-list1) cl-list2) ((null cl-list2) cl-list1) |
781 ((equal cl-list1 cl-list2) cl-list1) | |
782 (t | |
783 (or (>= (length cl-list1) (length cl-list2)) | |
784 (setq cl-list1 (prog1 cl-list2 (setq cl-list2 cl-list1)))) | |
785 (while cl-list2 | |
786 (if (or cl-keys (numberp (car cl-list2))) | |
787 (setq cl-list1 (apply 'adjoin (car cl-list2) cl-list1 cl-keys)) | |
788 (or (memq (car cl-list2) cl-list1) | |
47661
025c490d435b
(cl-push, cl-pop): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42964
diff
changeset
|
789 (push (car cl-list2) cl-list1))) |
025c490d435b
(cl-push, cl-pop): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42964
diff
changeset
|
790 (pop cl-list2)) |
4355 | 791 cl-list1))) |
792 | |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
793 ;;;###autoload |
4355 | 794 (defun nunion (cl-list1 cl-list2 &rest cl-keys) |
795 "Combine LIST1 and LIST2 using a set-union operation. | |
796 The result list contains all items that appear in either LIST1 or LIST2. | |
797 This is a destructive function; it reuses the storage of LIST1 and LIST2 | |
798 whenever possible. | |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
799 \nKeywords supported: :test :test-not :key |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
800 \n(fn LIST1 LIST2 [KEYWORD VALUE]...)" |
4355 | 801 (cond ((null cl-list1) cl-list2) ((null cl-list2) cl-list1) |
802 (t (apply 'union cl-list1 cl-list2 cl-keys)))) | |
803 | |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
804 ;;;###autoload |
4355 | 805 (defun intersection (cl-list1 cl-list2 &rest cl-keys) |
806 "Combine LIST1 and LIST2 using a set-intersection operation. | |
807 The result list contains all items that appear in both LIST1 and LIST2. | |
808 This is a non-destructive function; it makes a copy of the data if necessary | |
809 to avoid corrupting the original LIST1 and LIST2. | |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
810 \nKeywords supported: :test :test-not :key |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
811 \n(fn LIST1 LIST2 [KEYWORD VALUE]...)" |
4355 | 812 (and cl-list1 cl-list2 |
813 (if (equal cl-list1 cl-list2) cl-list1 | |
814 (cl-parsing-keywords (:key) (:test :test-not) | |
815 (let ((cl-res nil)) | |
816 (or (>= (length cl-list1) (length cl-list2)) | |
817 (setq cl-list1 (prog1 cl-list2 (setq cl-list2 cl-list1)))) | |
818 (while cl-list2 | |
819 (if (if (or cl-keys (numberp (car cl-list2))) | |
820 (apply 'member* (cl-check-key (car cl-list2)) | |
821 cl-list1 cl-keys) | |
822 (memq (car cl-list2) cl-list1)) | |
47661
025c490d435b
(cl-push, cl-pop): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42964
diff
changeset
|
823 (push (car cl-list2) cl-res)) |
025c490d435b
(cl-push, cl-pop): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42964
diff
changeset
|
824 (pop cl-list2)) |
4355 | 825 cl-res))))) |
826 | |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
827 ;;;###autoload |
4355 | 828 (defun nintersection (cl-list1 cl-list2 &rest cl-keys) |
829 "Combine LIST1 and LIST2 using a set-intersection operation. | |
830 The result list contains all items that appear in both LIST1 and LIST2. | |
831 This is a destructive function; it reuses the storage of LIST1 and LIST2 | |
832 whenever possible. | |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
833 \nKeywords supported: :test :test-not :key |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
834 \n(fn LIST1 LIST2 [KEYWORD VALUE]...)" |
4355 | 835 (and cl-list1 cl-list2 (apply 'intersection cl-list1 cl-list2 cl-keys))) |
836 | |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
837 ;;;###autoload |
4355 | 838 (defun set-difference (cl-list1 cl-list2 &rest cl-keys) |
839 "Combine LIST1 and LIST2 using a set-difference operation. | |
840 The result list contains all items that appear in LIST1 but not LIST2. | |
841 This is a non-destructive function; it makes a copy of the data if necessary | |
842 to avoid corrupting the original LIST1 and LIST2. | |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
843 \nKeywords supported: :test :test-not :key |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
844 \n(fn LIST1 LIST2 [KEYWORD VALUE]...)" |
4355 | 845 (if (or (null cl-list1) (null cl-list2)) cl-list1 |
846 (cl-parsing-keywords (:key) (:test :test-not) | |
847 (let ((cl-res nil)) | |
848 (while cl-list1 | |
849 (or (if (or cl-keys (numberp (car cl-list1))) | |
850 (apply 'member* (cl-check-key (car cl-list1)) | |
851 cl-list2 cl-keys) | |
852 (memq (car cl-list1) cl-list2)) | |
47661
025c490d435b
(cl-push, cl-pop): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42964
diff
changeset
|
853 (push (car cl-list1) cl-res)) |
025c490d435b
(cl-push, cl-pop): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42964
diff
changeset
|
854 (pop cl-list1)) |
4355 | 855 cl-res)))) |
856 | |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
857 ;;;###autoload |
4355 | 858 (defun nset-difference (cl-list1 cl-list2 &rest cl-keys) |
859 "Combine LIST1 and LIST2 using a set-difference operation. | |
860 The result list contains all items that appear in LIST1 but not LIST2. | |
861 This is a destructive function; it reuses the storage of LIST1 and LIST2 | |
862 whenever possible. | |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
863 \nKeywords supported: :test :test-not :key |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
864 \n(fn LIST1 LIST2 [KEYWORD VALUE]...)" |
4355 | 865 (if (or (null cl-list1) (null cl-list2)) cl-list1 |
866 (apply 'set-difference cl-list1 cl-list2 cl-keys))) | |
867 | |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
868 ;;;###autoload |
4355 | 869 (defun set-exclusive-or (cl-list1 cl-list2 &rest cl-keys) |
870 "Combine LIST1 and LIST2 using a set-exclusive-or operation. | |
871 The result list contains all items that appear in exactly one of LIST1, LIST2. | |
872 This is a non-destructive function; it makes a copy of the data if necessary | |
873 to avoid corrupting the original LIST1 and LIST2. | |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
874 \nKeywords supported: :test :test-not :key |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
875 \n(fn LIST1 LIST2 [KEYWORD VALUE]...)" |
4355 | 876 (cond ((null cl-list1) cl-list2) ((null cl-list2) cl-list1) |
877 ((equal cl-list1 cl-list2) nil) | |
878 (t (append (apply 'set-difference cl-list1 cl-list2 cl-keys) | |
879 (apply 'set-difference cl-list2 cl-list1 cl-keys))))) | |
880 | |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
881 ;;;###autoload |
4355 | 882 (defun nset-exclusive-or (cl-list1 cl-list2 &rest cl-keys) |
883 "Combine LIST1 and LIST2 using a set-exclusive-or operation. | |
884 The result list contains all items that appear in exactly one of LIST1, LIST2. | |
885 This is a destructive function; it reuses the storage of LIST1 and LIST2 | |
886 whenever possible. | |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
887 \nKeywords supported: :test :test-not :key |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
888 \n(fn LIST1 LIST2 [KEYWORD VALUE]...)" |
4355 | 889 (cond ((null cl-list1) cl-list2) ((null cl-list2) cl-list1) |
890 ((equal cl-list1 cl-list2) nil) | |
891 (t (nconc (apply 'nset-difference cl-list1 cl-list2 cl-keys) | |
892 (apply 'nset-difference cl-list2 cl-list1 cl-keys))))) | |
893 | |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
894 ;;;###autoload |
4355 | 895 (defun subsetp (cl-list1 cl-list2 &rest cl-keys) |
62426
c5a3c48f99b5
(subsetp, tree-equal): Doc fixes.
Juanma Barranquero <lekktu@gmail.com>
parents:
52401
diff
changeset
|
896 "Return true if LIST1 is a subset of LIST2. |
4355 | 897 I.e., if every element of LIST1 also appears in LIST2. |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
898 \nKeywords supported: :test :test-not :key |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
899 \n(fn LIST1 LIST2 [KEYWORD VALUE]...)" |
4355 | 900 (cond ((null cl-list1) t) ((null cl-list2) nil) |
901 ((equal cl-list1 cl-list2) t) | |
902 (t (cl-parsing-keywords (:key) (:test :test-not) | |
903 (while (and cl-list1 | |
904 (apply 'member* (cl-check-key (car cl-list1)) | |
905 cl-list2 cl-keys)) | |
47661
025c490d435b
(cl-push, cl-pop): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42964
diff
changeset
|
906 (pop cl-list1)) |
4355 | 907 (null cl-list1))))) |
908 | |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
909 ;;;###autoload |
4355 | 910 (defun subst-if (cl-new cl-pred cl-tree &rest cl-keys) |
911 "Substitute NEW for elements matching PREDICATE in TREE (non-destructively). | |
912 Return a copy of TREE with all matching elements replaced by NEW. | |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
913 \nKeywords supported: :key |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
914 \n(fn NEW PREDICATE TREE [KEYWORD VALUE]...)" |
28824
add63b27c709
Doc fixes; mainly avoid duplicating arg
Dave Love <fx@gnu.org>
parents:
16057
diff
changeset
|
915 (apply 'sublis (list (cons nil cl-new)) cl-tree :if cl-pred cl-keys)) |
4355 | 916 |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
917 ;;;###autoload |
4355 | 918 (defun subst-if-not (cl-new cl-pred cl-tree &rest cl-keys) |
919 "Substitute NEW for elts not matching PREDICATE in TREE (non-destructively). | |
920 Return a copy of TREE with all non-matching elements replaced by NEW. | |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
921 \nKeywords supported: :key |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
922 \n(fn NEW PREDICATE TREE [KEYWORD VALUE]...)" |
28824
add63b27c709
Doc fixes; mainly avoid duplicating arg
Dave Love <fx@gnu.org>
parents:
16057
diff
changeset
|
923 (apply 'sublis (list (cons nil cl-new)) cl-tree :if-not cl-pred cl-keys)) |
4355 | 924 |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
925 ;;;###autoload |
4355 | 926 (defun nsubst (cl-new cl-old cl-tree &rest cl-keys) |
927 "Substitute NEW for OLD everywhere in TREE (destructively). | |
928 Any element of TREE which is `eql' to OLD is changed to NEW (via a call | |
929 to `setcar'). | |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
930 \nKeywords supported: :test :test-not :key |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
931 \n(fn NEW OLD TREE [KEYWORD VALUE]...)" |
4355 | 932 (apply 'nsublis (list (cons cl-old cl-new)) cl-tree cl-keys)) |
933 | |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
934 ;;;###autoload |
4355 | 935 (defun nsubst-if (cl-new cl-pred cl-tree &rest cl-keys) |
936 "Substitute NEW for elements matching PREDICATE in TREE (destructively). | |
937 Any element of TREE which matches is changed to NEW (via a call to `setcar'). | |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
938 \nKeywords supported: :key |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
939 \n(fn NEW PREDICATE TREE [KEYWORD VALUE]...)" |
28824
add63b27c709
Doc fixes; mainly avoid duplicating arg
Dave Love <fx@gnu.org>
parents:
16057
diff
changeset
|
940 (apply 'nsublis (list (cons nil cl-new)) cl-tree :if cl-pred cl-keys)) |
4355 | 941 |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
942 ;;;###autoload |
4355 | 943 (defun nsubst-if-not (cl-new cl-pred cl-tree &rest cl-keys) |
944 "Substitute NEW for elements not matching PREDICATE in TREE (destructively). | |
945 Any element of TREE which matches is changed to NEW (via a call to `setcar'). | |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
946 \nKeywords supported: :key |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
947 \n(fn NEW PREDICATE TREE [KEYWORD VALUE]...)" |
28824
add63b27c709
Doc fixes; mainly avoid duplicating arg
Dave Love <fx@gnu.org>
parents:
16057
diff
changeset
|
948 (apply 'nsublis (list (cons nil cl-new)) cl-tree :if-not cl-pred cl-keys)) |
4355 | 949 |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
950 ;;;###autoload |
4355 | 951 (defun sublis (cl-alist cl-tree &rest cl-keys) |
952 "Perform substitutions indicated by ALIST in TREE (non-destructively). | |
953 Return a copy of TREE with all matching elements replaced. | |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
954 \nKeywords supported: :test :test-not :key |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
955 \n(fn ALIST TREE [KEYWORD VALUE]...)" |
4355 | 956 (cl-parsing-keywords (:test :test-not :key :if :if-not) () |
957 (cl-sublis-rec cl-tree))) | |
958 | |
959 (defvar cl-alist) | |
960 (defun cl-sublis-rec (cl-tree) ; uses cl-alist/key/test*/if* | |
961 (let ((cl-temp (cl-check-key cl-tree)) (cl-p cl-alist)) | |
962 (while (and cl-p (not (cl-check-test-nokey (car (car cl-p)) cl-temp))) | |
963 (setq cl-p (cdr cl-p))) | |
964 (if cl-p (cdr (car cl-p)) | |
965 (if (consp cl-tree) | |
966 (let ((cl-a (cl-sublis-rec (car cl-tree))) | |
967 (cl-d (cl-sublis-rec (cdr cl-tree)))) | |
968 (if (and (eq cl-a (car cl-tree)) (eq cl-d (cdr cl-tree))) | |
969 cl-tree | |
970 (cons cl-a cl-d))) | |
971 cl-tree)))) | |
972 | |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
973 ;;;###autoload |
4355 | 974 (defun nsublis (cl-alist cl-tree &rest cl-keys) |
975 "Perform substitutions indicated by ALIST in TREE (destructively). | |
976 Any matching element of TREE is changed via a call to `setcar'. | |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
977 \nKeywords supported: :test :test-not :key |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
978 \n(fn ALIST TREE [KEYWORD VALUE]...)" |
4355 | 979 (cl-parsing-keywords (:test :test-not :key :if :if-not) () |
980 (let ((cl-hold (list cl-tree))) | |
981 (cl-nsublis-rec cl-hold) | |
982 (car cl-hold)))) | |
983 | |
984 (defun cl-nsublis-rec (cl-tree) ; uses cl-alist/temp/p/key/test*/if* | |
985 (while (consp cl-tree) | |
986 (let ((cl-temp (cl-check-key (car cl-tree))) (cl-p cl-alist)) | |
987 (while (and cl-p (not (cl-check-test-nokey (car (car cl-p)) cl-temp))) | |
988 (setq cl-p (cdr cl-p))) | |
989 (if cl-p (setcar cl-tree (cdr (car cl-p))) | |
990 (if (consp (car cl-tree)) (cl-nsublis-rec (car cl-tree)))) | |
991 (setq cl-temp (cl-check-key (cdr cl-tree)) cl-p cl-alist) | |
992 (while (and cl-p (not (cl-check-test-nokey (car (car cl-p)) cl-temp))) | |
993 (setq cl-p (cdr cl-p))) | |
994 (if cl-p | |
995 (progn (setcdr cl-tree (cdr (car cl-p))) (setq cl-tree nil)) | |
996 (setq cl-tree (cdr cl-tree)))))) | |
997 | |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
998 ;;;###autoload |
4355 | 999 (defun tree-equal (cl-x cl-y &rest cl-keys) |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
1000 "Return t if trees TREE1 and TREE2 have `eql' leaves. |
4355 | 1001 Atoms are compared by `eql'; cons cells are compared recursively. |
62555
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
1002 \nKeywords supported: :test :test-not :key |
e74fa19e333d
(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
Juanma Barranquero <lekktu@gmail.com>
parents:
62426
diff
changeset
|
1003 \n(fn TREE1 TREE2 [KEYWORD VALUE]...)" |
4355 | 1004 (cl-parsing-keywords (:test :test-not :key) () |
1005 (cl-tree-equal-rec cl-x cl-y))) | |
1006 | |
1007 (defun cl-tree-equal-rec (cl-x cl-y) | |
1008 (while (and (consp cl-x) (consp cl-y) | |
1009 (cl-tree-equal-rec (car cl-x) (car cl-y))) | |
1010 (setq cl-x (cdr cl-x) cl-y (cdr cl-y))) | |
1011 (and (not (consp cl-x)) (not (consp cl-y)) (cl-check-match cl-x cl-y))) | |
1012 | |
1013 | |
1014 (run-hooks 'cl-seq-load-hook) | |
1015 | |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
1016 ;; Local variables: |
85726
370f231ade90
Unify local variable section, and set byte-compile-warnings to `(not
Glenn Morris <rgm@gnu.org>
parents:
82140
diff
changeset
|
1017 ;; byte-compile-dynamic: t |
370f231ade90
Unify local variable section, and set byte-compile-warnings to `(not
Glenn Morris <rgm@gnu.org>
parents:
82140
diff
changeset
|
1018 ;; byte-compile-warnings: (not cl-functions) |
81633
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
1019 ;; generated-autoload-file: "cl-loaddefs.el" |
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
1020 ;; End: |
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
1021 |
eb7ed3625d94
Set generated-autoload-file to cl-loaddefs.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
1022 ;; arch-tag: ec1cc072-9006-4225-b6ba-d6b07ed1710c |
4355 | 1023 ;;; cl-seq.el ends here |