annotate lisp/emacs-lisp/cl-seq.el @ 112425:9f7614f1a892

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