annotate lisp/emacs-lisp/cl-seq.el @ 96649:bb31f77bf63f

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