annotate lisp/emacs-lisp/cl-seq.el @ 110015:280c8ae2476d

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