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