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