annotate lisp/cl/cl-seq.el @ 172:a38aed19690b

Added tag r20-3b12 for changeset 929b76928fce
author cvs
date Mon, 13 Aug 2007 09:47:55 +0200
parents ac2d302a0011
children eb5470882647
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; cl-seq.el --- Common Lisp extensions for GNU Emacs Lisp (part three)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1993 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Author: Dave Gillespie <daveg@synaptics.com>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Version: 2.02
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; Keywords: extensions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; along with XEmacs; see the file COPYING. If not, write to the Free
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
23 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
24 ;; 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
26 ;;; Synched up with: FSF 19.34.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; These are extensions to Emacs Lisp that provide a degree of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;; Common Lisp compatibility, beyond what is already built-in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;; in Emacs Lisp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;; This package was written by Dave Gillespie; it is a complete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;; rewrite of Cesar Quiroz's original cl.el package of December 1986.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;; This package works with Emacs 18, Emacs 19, and Lucid Emacs 19.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;; Bug reports, comments, and suggestions are welcome!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;; This file contains the Common Lisp sequence and list functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;; which take keyword arguments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;; See cl.el for Change Log.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (or (memq 'cl-19 features)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (error "Tried to load `cl-seq' before `cl'!"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;;; We define these here so that this file can compile without having
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;;; loaded the cl.el file already.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (defmacro cl-push (x place) (list 'setq place (list 'cons x place)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (defmacro cl-pop (place)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (list 'car (list 'prog1 place (list 'setq place (list 'cdr place)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ;;; Keyword parsing. This is special-cased here so that we can compile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ;;; this file independent from cl-macs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (defmacro cl-parsing-keywords (kwords other-keys &rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (cons
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 'let*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (cons (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (lambda (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (let* ((var (if (consp x) (car x) x))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (mem (list 'car (list 'cdr (list 'memq (list 'quote var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 'cl-keys)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (if (eq var ':test-not)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (setq mem (list 'and mem (list 'setq 'cl-test mem) t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (if (eq var ':if-not)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (setq mem (list 'and mem (list 'setq 'cl-if mem) t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (list (intern
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (format "cl-%s" (substring (symbol-name var) 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (if (consp x) (list 'or mem (car (cdr x))) mem)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 kwords)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (append
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (and (not (eq other-keys t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (list 'let '((cl-keys-temp cl-keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (list 'while 'cl-keys-temp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (list 'or (list 'memq '(car cl-keys-temp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (list 'quote
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (lambda (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (if (consp x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (car x) x)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (append kwords
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 other-keys))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 '(car (cdr (memq (quote :allow-other-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 cl-keys)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 '(error "Bad keyword argument %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (car cl-keys-temp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 '(setq cl-keys-temp (cdr (cdr cl-keys-temp)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 body))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (put 'cl-parsing-keywords 'lisp-indent-function 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (put 'cl-parsing-keywords 'edebug-form-spec '(sexp sexp &rest form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (defmacro cl-check-key (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (list 'if 'cl-key (list 'funcall 'cl-key x) x))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (defmacro cl-check-test-nokey (item x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (list 'cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (list 'cl-test
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (list 'eq (list 'not (list 'funcall 'cl-test item x))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 'cl-test-not))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (list 'cl-if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (list 'eq (list 'not (list 'funcall 'cl-if x)) 'cl-if-not))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (list 't (list 'if (list 'numberp item)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (list 'equal item x) (list 'eq item x)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (defmacro cl-check-test (item x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (list 'cl-check-test-nokey item (list 'cl-check-key x)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (defmacro cl-check-match (x y)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (setq x (list 'cl-check-key x) y (list 'cl-check-key y))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (list 'if 'cl-test
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (list 'eq (list 'not (list 'funcall 'cl-test x y)) 'cl-test-not)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (list 'if (list 'numberp x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (list 'equal x y) (list 'eq x y))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (put 'cl-check-key 'edebug-form-spec 'edebug-forms)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (put 'cl-check-test 'edebug-form-spec 'edebug-forms)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (put 'cl-check-test-nokey 'edebug-form-spec 'edebug-forms)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (put 'cl-check-match 'edebug-form-spec 'edebug-forms)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (defvar cl-test) (defvar cl-test-not)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (defvar cl-if) (defvar cl-if-not)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (defvar cl-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (defun reduce (cl-func cl-seq &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 "Reduce two-argument FUNCTION across SEQUENCE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 Keywords supported: :start :end :from-end :initial-value :key"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (cl-parsing-keywords (:from-end (:start 0) :end :initial-value :key) ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (or (listp cl-seq) (setq cl-seq (append cl-seq nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (setq cl-seq (subseq cl-seq cl-start cl-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (if cl-from-end (setq cl-seq (nreverse cl-seq)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (let ((cl-accum (cond ((memq ':initial-value cl-keys) cl-initial-value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (cl-seq (cl-check-key (cl-pop cl-seq)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (t (funcall cl-func)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (if cl-from-end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (while cl-seq
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (setq cl-accum (funcall cl-func (cl-check-key (cl-pop cl-seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 cl-accum)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (while cl-seq
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (setq cl-accum (funcall cl-func cl-accum
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (cl-check-key (cl-pop cl-seq))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 cl-accum)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (defun fill (seq item &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 "Fill the elements of SEQ with ITEM.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 Keywords supported: :start :end"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (cl-parsing-keywords ((:start 0) :end) ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (if (listp seq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (let ((p (nthcdr cl-start seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (n (if cl-end (- cl-end cl-start) 8000000)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (while (and p (>= (setq n (1- n)) 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (setcar p item)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (setq p (cdr p))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (or cl-end (setq cl-end (length seq)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (if (and (= cl-start 0) (= cl-end (length seq)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (fillarray seq item)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (while (< cl-start cl-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (aset seq cl-start item)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (setq cl-start (1+ cl-start)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (defun replace (cl-seq1 cl-seq2 &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 "Replace the elements of SEQ1 with the elements of SEQ2.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 SEQ1 is destructively modified, then returned.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 Keywords supported: :start1 :end1 :start2 :end2"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (cl-parsing-keywords ((:start1 0) :end1 (:start2 0) :end2) ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (if (and (eq cl-seq1 cl-seq2) (<= cl-start2 cl-start1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (or (= cl-start1 cl-start2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (let* ((cl-len (length cl-seq1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (cl-n (min (- (or cl-end1 cl-len) cl-start1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (- (or cl-end2 cl-len) cl-start2))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (while (>= (setq cl-n (1- cl-n)) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (cl-set-elt cl-seq1 (+ cl-start1 cl-n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (elt cl-seq2 (+ cl-start2 cl-n))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (if (listp cl-seq1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (let ((cl-p1 (nthcdr cl-start1 cl-seq1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (cl-n1 (if cl-end1 (- cl-end1 cl-start1) 4000000)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (if (listp cl-seq2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (let ((cl-p2 (nthcdr cl-start2 cl-seq2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (cl-n (min cl-n1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (if cl-end2 (- cl-end2 cl-start2) 4000000))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (while (and cl-p1 cl-p2 (>= (setq cl-n (1- cl-n)) 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (setcar cl-p1 (car cl-p2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (setq cl-p1 (cdr cl-p1) cl-p2 (cdr cl-p2))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (setq cl-end2 (min (or cl-end2 (length cl-seq2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (+ cl-start2 cl-n1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (while (and cl-p1 (< cl-start2 cl-end2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (setcar cl-p1 (aref cl-seq2 cl-start2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (setq cl-p1 (cdr cl-p1) cl-start2 (1+ cl-start2)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (setq cl-end1 (min (or cl-end1 (length cl-seq1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (+ cl-start1 (- (or cl-end2 (length cl-seq2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 cl-start2))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (if (listp cl-seq2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (let ((cl-p2 (nthcdr cl-start2 cl-seq2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (while (< cl-start1 cl-end1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (aset cl-seq1 cl-start1 (car cl-p2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (setq cl-p2 (cdr cl-p2) cl-start1 (1+ cl-start1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (while (< cl-start1 cl-end1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (aset cl-seq1 cl-start1 (aref cl-seq2 cl-start2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (setq cl-start2 (1+ cl-start2) cl-start1 (1+ cl-start1))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 cl-seq1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (defun remove* (cl-item cl-seq &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 "Remove all occurrences of ITEM in SEQ.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 This is a non-destructive function; it makes a copy of SEQ if necessary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 to avoid corrupting the original SEQ.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 Keywords supported: :test :test-not :key :count :start :end :from-end"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (cl-parsing-keywords (:test :test-not :key :if :if-not :count :from-end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (:start 0) :end) ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (if (<= (or cl-count (setq cl-count 8000000)) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 cl-seq
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (if (or (nlistp cl-seq) (and cl-from-end (< cl-count 4000000)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (let ((cl-i (cl-position cl-item cl-seq cl-start cl-end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 cl-from-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (if cl-i
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (let ((cl-res (apply 'delete* cl-item (append cl-seq nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (append (if cl-from-end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (list ':end (1+ cl-i))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (list ':start cl-i))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 cl-keys))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (if (listp cl-seq) cl-res
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (if (stringp cl-seq) (concat cl-res) (vconcat cl-res))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 cl-seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (setq cl-end (- (or cl-end 8000000) cl-start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (if (= cl-start 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (while (and cl-seq (> cl-end 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (cl-check-test cl-item (car cl-seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (setq cl-end (1- cl-end) cl-seq (cdr cl-seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (> (setq cl-count (1- cl-count)) 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (if (and (> cl-count 0) (> cl-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (let ((cl-p (if (> cl-start 0) (nthcdr cl-start cl-seq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (setq cl-end (1- cl-end)) (cdr cl-seq))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (while (and cl-p (> cl-end 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (not (cl-check-test cl-item (car cl-p))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (setq cl-p (cdr cl-p) cl-end (1- cl-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (if (and cl-p (> cl-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (nconc (ldiff cl-seq cl-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (if (= cl-count 1) (cdr cl-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (and (cdr cl-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (apply 'delete* cl-item
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (copy-sequence (cdr cl-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 ':start 0 ':end (1- cl-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 ':count (1- cl-count) cl-keys))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 cl-seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 cl-seq)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (defun remove-if (cl-pred cl-list &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 "Remove all items satisfying PREDICATE in SEQ.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 This is a non-destructive function; it makes a copy of SEQ if necessary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 to avoid corrupting the original SEQ.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 Keywords supported: :key :count :start :end :from-end"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (apply 'remove* nil cl-list ':if cl-pred cl-keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (defun remove-if-not (cl-pred cl-list &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 "Remove all items not satisfying PREDICATE in SEQ.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 This is a non-destructive function; it makes a copy of SEQ if necessary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 to avoid corrupting the original SEQ.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 Keywords supported: :key :count :start :end :from-end"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (apply 'remove* nil cl-list ':if-not cl-pred cl-keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (defun delete* (cl-item cl-seq &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 "Remove all occurrences of ITEM in SEQ.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 This is a destructive function; it reuses the storage of SEQ whenever possible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 Keywords supported: :test :test-not :key :count :start :end :from-end"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (cl-parsing-keywords (:test :test-not :key :if :if-not :count :from-end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (:start 0) :end) ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (if (<= (or cl-count (setq cl-count 8000000)) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 cl-seq
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (if (listp cl-seq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (if (and cl-from-end (< cl-count 4000000))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (let (cl-i)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (while (and (>= (setq cl-count (1- cl-count)) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (setq cl-i (cl-position cl-item cl-seq cl-start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 cl-end cl-from-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (if (= cl-i 0) (setq cl-seq (cdr cl-seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (let ((cl-tail (nthcdr (1- cl-i) cl-seq)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (setcdr cl-tail (cdr (cdr cl-tail)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (setq cl-end cl-i))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 cl-seq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (setq cl-end (- (or cl-end 8000000) cl-start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (if (= cl-start 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (while (and cl-seq
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (> cl-end 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (cl-check-test cl-item (car cl-seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (setq cl-end (1- cl-end) cl-seq (cdr cl-seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (> (setq cl-count (1- cl-count)) 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (setq cl-end (1- cl-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (setq cl-start (1- cl-start)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (if (and (> cl-count 0) (> cl-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (let ((cl-p (nthcdr cl-start cl-seq)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (while (and (cdr cl-p) (> cl-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (if (cl-check-test cl-item (car (cdr cl-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (setcdr cl-p (cdr (cdr cl-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (if (= (setq cl-count (1- cl-count)) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (setq cl-end 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (setq cl-p (cdr cl-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (setq cl-end (1- cl-end)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 cl-seq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (apply 'remove* cl-item cl-seq cl-keys)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (defun delete-if (cl-pred cl-list &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 "Remove all items satisfying PREDICATE in SEQ.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 This is a destructive function; it reuses the storage of SEQ whenever possible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 Keywords supported: :key :count :start :end :from-end"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (apply 'delete* nil cl-list ':if cl-pred cl-keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 (defun delete-if-not (cl-pred cl-list &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 "Remove all items not satisfying PREDICATE in SEQ.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 This is a destructive function; it reuses the storage of SEQ whenever possible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 Keywords supported: :key :count :start :end :from-end"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (apply 'delete* nil cl-list ':if-not cl-pred cl-keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (or (and (fboundp 'delete) (subrp (symbol-function 'delete)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (defalias 'delete (function (lambda (x y) (delete* x y ':test 'equal)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 (defun remove (x y) (remove* x y ':test 'equal))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (defun remq (x y) (if (memq x y) (delq x (copy-list y)) y))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (defun remove-duplicates (cl-seq &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 "Return a copy of SEQ with all duplicate elements removed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 Keywords supported: :test :test-not :key :start :end :from-end"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (cl-delete-duplicates cl-seq cl-keys t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (defun delete-duplicates (cl-seq &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 "Remove all duplicate elements from SEQ (destructively).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 Keywords supported: :test :test-not :key :start :end :from-end"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (cl-delete-duplicates cl-seq cl-keys nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 (defun cl-delete-duplicates (cl-seq cl-keys cl-copy)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (if (listp cl-seq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (cl-parsing-keywords (:test :test-not :key (:start 0) :end :from-end :if)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (if cl-from-end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (let ((cl-p (nthcdr cl-start cl-seq)) cl-i)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (setq cl-end (- (or cl-end (length cl-seq)) cl-start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (while (> cl-end 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (setq cl-i 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (while (setq cl-i (cl-position (cl-check-key (car cl-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 (cdr cl-p) cl-i (1- cl-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 (if cl-copy (setq cl-seq (copy-sequence cl-seq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 cl-p (nthcdr cl-start cl-seq) cl-copy nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (let ((cl-tail (nthcdr cl-i cl-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 (setcdr cl-tail (cdr (cdr cl-tail))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (setq cl-end (1- cl-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (setq cl-p (cdr cl-p) cl-end (1- cl-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 cl-start (1+ cl-start)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 cl-seq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (setq cl-end (- (or cl-end (length cl-seq)) cl-start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (while (and (cdr cl-seq) (= cl-start 0) (> cl-end 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 (cl-position (cl-check-key (car cl-seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 (cdr cl-seq) 0 (1- cl-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 (setq cl-seq (cdr cl-seq) cl-end (1- cl-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (let ((cl-p (if (> cl-start 0) (nthcdr (1- cl-start) cl-seq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 (setq cl-end (1- cl-end) cl-start 1) cl-seq)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 (while (and (cdr (cdr cl-p)) (> cl-end 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 (if (cl-position (cl-check-key (car (cdr cl-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 (cdr (cdr cl-p)) 0 (1- cl-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 (if cl-copy (setq cl-seq (copy-sequence cl-seq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 cl-p (nthcdr (1- cl-start) cl-seq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 cl-copy nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (setcdr cl-p (cdr (cdr cl-p))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (setq cl-p (cdr cl-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 (setq cl-end (1- cl-end) cl-start (1+ cl-start)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 cl-seq)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 (let ((cl-res (cl-delete-duplicates (append cl-seq nil) cl-keys nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 (if (stringp cl-seq) (concat cl-res) (vconcat cl-res)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 (defun substitute (cl-new cl-old cl-seq &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 "Substitute NEW for OLD in SEQ.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 This is a non-destructive function; it makes a copy of SEQ if necessary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 to avoid corrupting the original SEQ.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 Keywords supported: :test :test-not :key :count :start :end :from-end"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 (cl-parsing-keywords (:test :test-not :key :if :if-not :count
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 (:start 0) :end :from-end) ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (if (or (eq cl-old cl-new)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 (<= (or cl-count (setq cl-from-end nil cl-count 8000000)) 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 cl-seq
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 (let ((cl-i (cl-position cl-old cl-seq cl-start cl-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (if (not cl-i)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 cl-seq
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 (setq cl-seq (copy-sequence cl-seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 (or cl-from-end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 (progn (cl-set-elt cl-seq cl-i cl-new)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 (setq cl-i (1+ cl-i) cl-count (1- cl-count))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 (apply 'nsubstitute cl-new cl-old cl-seq ':count cl-count
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 ':start cl-i cl-keys))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 (defun substitute-if (cl-new cl-pred cl-list &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 "Substitute NEW for all items satisfying PREDICATE in SEQ.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 This is a non-destructive function; it makes a copy of SEQ if necessary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 to avoid corrupting the original SEQ.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 Keywords supported: :key :count :start :end :from-end"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 (apply 'substitute cl-new nil cl-list ':if cl-pred cl-keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (defun substitute-if-not (cl-new cl-pred cl-list &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 "Substitute NEW for all items not satisfying PREDICATE in SEQ.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 This is a non-destructive function; it makes a copy of SEQ if necessary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 to avoid corrupting the original SEQ.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 Keywords supported: :key :count :start :end :from-end"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 (apply 'substitute cl-new nil cl-list ':if-not cl-pred cl-keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 (defun nsubstitute (cl-new cl-old cl-seq &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 "Substitute NEW for OLD in SEQ.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 This is a destructive function; it reuses the storage of SEQ whenever possible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 Keywords supported: :test :test-not :key :count :start :end :from-end"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (cl-parsing-keywords (:test :test-not :key :if :if-not :count
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 (:start 0) :end :from-end) ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 (or (eq cl-old cl-new) (<= (or cl-count (setq cl-count 8000000)) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 (if (and (listp cl-seq) (or (not cl-from-end) (> cl-count 4000000)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (let ((cl-p (nthcdr cl-start cl-seq)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 (setq cl-end (- (or cl-end 8000000) cl-start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (while (and cl-p (> cl-end 0) (> cl-count 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (if (cl-check-test cl-old (car cl-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 (setcar cl-p cl-new)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (setq cl-count (1- cl-count))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 (setq cl-p (cdr cl-p) cl-end (1- cl-end))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (or cl-end (setq cl-end (length cl-seq)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 (if cl-from-end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (while (and (< cl-start cl-end) (> cl-count 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (setq cl-end (1- cl-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (if (cl-check-test cl-old (elt cl-seq cl-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (cl-set-elt cl-seq cl-end cl-new)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 (setq cl-count (1- cl-count)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 (while (and (< cl-start cl-end) (> cl-count 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 (if (cl-check-test cl-old (aref cl-seq cl-start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 (aset cl-seq cl-start cl-new)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 (setq cl-count (1- cl-count))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 (setq cl-start (1+ cl-start))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 cl-seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 (defun nsubstitute-if (cl-new cl-pred cl-list &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 "Substitute NEW for all items satisfying PREDICATE in SEQ.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 This is a destructive function; it reuses the storage of SEQ whenever possible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 Keywords supported: :key :count :start :end :from-end"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 (apply 'nsubstitute cl-new nil cl-list ':if cl-pred cl-keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 (defun nsubstitute-if-not (cl-new cl-pred cl-list &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 "Substitute NEW for all items not satisfying PREDICATE in SEQ.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 This is a destructive function; it reuses the storage of SEQ whenever possible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 Keywords supported: :key :count :start :end :from-end"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 (apply 'nsubstitute cl-new nil cl-list ':if-not cl-pred cl-keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (defun find (cl-item cl-seq &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 "Find the first occurrence of ITEM in LIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 Return the matching ITEM, or nil if not found.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 Keywords supported: :test :test-not :key :start :end :from-end"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 (let ((cl-pos (apply 'position cl-item cl-seq cl-keys)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 (and cl-pos (elt cl-seq cl-pos))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 (defun find-if (cl-pred cl-list &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 "Find the first item satisfying PREDICATE in LIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 Return the matching ITEM, or nil if not found.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 Keywords supported: :key :start :end :from-end"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 (apply 'find nil cl-list ':if cl-pred cl-keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (defun find-if-not (cl-pred cl-list &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 "Find the first item not satisfying PREDICATE in LIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 Return the matching ITEM, or nil if not found.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 Keywords supported: :key :start :end :from-end"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (apply 'find nil cl-list ':if-not cl-pred cl-keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 (defun position (cl-item cl-seq &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 "Find the first occurrence of ITEM in LIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 Return the index of the matching item, or nil if not found.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 Keywords supported: :test :test-not :key :start :end :from-end"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 (cl-parsing-keywords (:test :test-not :key :if :if-not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 (:start 0) :end :from-end) ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 (cl-position cl-item cl-seq cl-start cl-end cl-from-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 (defun cl-position (cl-item cl-seq cl-start &optional cl-end cl-from-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 (if (listp cl-seq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 (let ((cl-p (nthcdr cl-start cl-seq)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 (or cl-end (setq cl-end 8000000))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (let ((cl-res nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 (while (and cl-p (< cl-start cl-end) (or (not cl-res) cl-from-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 (if (cl-check-test cl-item (car cl-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 (setq cl-res cl-start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (setq cl-p (cdr cl-p) cl-start (1+ cl-start)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 cl-res))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (or cl-end (setq cl-end (length cl-seq)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 (if cl-from-end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 (while (and (>= (setq cl-end (1- cl-end)) cl-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (not (cl-check-test cl-item (aref cl-seq cl-end)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 (and (>= cl-end cl-start) cl-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (while (and (< cl-start cl-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 (not (cl-check-test cl-item (aref cl-seq cl-start))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 (setq cl-start (1+ cl-start)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 (and (< cl-start cl-end) cl-start))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 (defun position-if (cl-pred cl-list &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 "Find the first item satisfying PREDICATE in LIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 Return the index of the matching item, or nil if not found.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 Keywords supported: :key :start :end :from-end"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 (apply 'position nil cl-list ':if cl-pred cl-keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 (defun position-if-not (cl-pred cl-list &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 "Find the first item not satisfying PREDICATE in LIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 Return the index of the matching item, or nil if not found.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 Keywords supported: :key :start :end :from-end"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (apply 'position nil cl-list ':if-not cl-pred cl-keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 (defun count (cl-item cl-seq &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 "Count the number of occurrences of ITEM in LIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 Keywords supported: :test :test-not :key :start :end"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 (cl-parsing-keywords (:test :test-not :key :if :if-not (:start 0) :end) ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 (let ((cl-count 0) cl-x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (or cl-end (setq cl-end (length cl-seq)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 (if (consp cl-seq) (setq cl-seq (nthcdr cl-start cl-seq)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 (while (< cl-start cl-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 (setq cl-x (if (consp cl-seq) (cl-pop cl-seq) (aref cl-seq cl-start)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 (if (cl-check-test cl-item cl-x) (setq cl-count (1+ cl-count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 (setq cl-start (1+ cl-start)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 cl-count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 (defun count-if (cl-pred cl-list &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 "Count the number of items satisfying PREDICATE in LIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 Keywords supported: :key :start :end"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 (apply 'count nil cl-list ':if cl-pred cl-keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 (defun count-if-not (cl-pred cl-list &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 "Count the number of items not satisfying PREDICATE in LIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 Keywords supported: :key :start :end"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 (apply 'count nil cl-list ':if-not cl-pred cl-keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 (defun mismatch (cl-seq1 cl-seq2 &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 "Compare SEQ1 with SEQ2, return index of first mismatching element.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 Return nil if the sequences match. If one sequence is a prefix of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 other, the return value indicates the end of the shorted sequence.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 Keywords supported: :test :test-not :key :start1 :end1 :start2 :end2 :from-end"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 (cl-parsing-keywords (:test :test-not :key :from-end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 (:start1 0) :end1 (:start2 0) :end2) ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 (or cl-end1 (setq cl-end1 (length cl-seq1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 (or cl-end2 (setq cl-end2 (length cl-seq2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 (if cl-from-end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 (while (and (< cl-start1 cl-end1) (< cl-start2 cl-end2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 (cl-check-match (elt cl-seq1 (1- cl-end1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 (elt cl-seq2 (1- cl-end2))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 (setq cl-end1 (1- cl-end1) cl-end2 (1- cl-end2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 (and (or (< cl-start1 cl-end1) (< cl-start2 cl-end2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 (1- cl-end1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 (let ((cl-p1 (and (listp cl-seq1) (nthcdr cl-start1 cl-seq1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 (cl-p2 (and (listp cl-seq2) (nthcdr cl-start2 cl-seq2))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 (while (and (< cl-start1 cl-end1) (< cl-start2 cl-end2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 (cl-check-match (if cl-p1 (car cl-p1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 (aref cl-seq1 cl-start1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 (if cl-p2 (car cl-p2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 (aref cl-seq2 cl-start2))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 (setq cl-p1 (cdr cl-p1) cl-p2 (cdr cl-p2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 cl-start1 (1+ cl-start1) cl-start2 (1+ cl-start2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 (and (or (< cl-start1 cl-end1) (< cl-start2 cl-end2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 cl-start1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 (defun search (cl-seq1 cl-seq2 &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 "Search for SEQ1 as a subsequence of SEQ2.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 Return the index of the leftmost element of the first match found;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 return nil if there are no matches.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 Keywords supported: :test :test-not :key :start1 :end1 :start2 :end2 :from-end"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 (cl-parsing-keywords (:test :test-not :key :from-end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 (:start1 0) :end1 (:start2 0) :end2) ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 (or cl-end1 (setq cl-end1 (length cl-seq1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 (or cl-end2 (setq cl-end2 (length cl-seq2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 (if (>= cl-start1 cl-end1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 (if cl-from-end cl-end2 cl-start2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 (let* ((cl-len (- cl-end1 cl-start1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 (cl-first (cl-check-key (elt cl-seq1 cl-start1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 (cl-if nil) cl-pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 (setq cl-end2 (- cl-end2 (1- cl-len)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 (while (and (< cl-start2 cl-end2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 (setq cl-pos (cl-position cl-first cl-seq2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 cl-start2 cl-end2 cl-from-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 (apply 'mismatch cl-seq1 cl-seq2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 ':start1 (1+ cl-start1) ':end1 cl-end1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 ':start2 (1+ cl-pos) ':end2 (+ cl-pos cl-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 ':from-end nil cl-keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 (if cl-from-end (setq cl-end2 cl-pos) (setq cl-start2 (1+ cl-pos))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 (and (< cl-start2 cl-end2) cl-pos)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 (defun sort* (cl-seq cl-pred &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 "Sort the argument SEQUENCE according to PREDICATE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 This is a destructive function; it reuses the storage of SEQUENCE if possible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 Keywords supported: :key"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 (if (nlistp cl-seq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 (replace cl-seq (apply 'sort* (append cl-seq nil) cl-pred cl-keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 (cl-parsing-keywords (:key) ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 (if (memq cl-key '(nil identity))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 (sort cl-seq cl-pred)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 (sort cl-seq (function (lambda (cl-x cl-y)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 (funcall cl-pred (funcall cl-key cl-x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 (funcall cl-key cl-y)))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 (defun stable-sort (cl-seq cl-pred &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 "Sort the argument SEQUENCE stably according to PREDICATE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 This is a destructive function; it reuses the storage of SEQUENCE if possible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 Keywords supported: :key"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 (apply 'sort* cl-seq cl-pred cl-keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 (defun merge (cl-type cl-seq1 cl-seq2 cl-pred &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 "Destructively merge the two sequences to produce a new sequence.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 TYPE is the sequence type to return, SEQ1 and SEQ2 are the two
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 argument sequences, and PRED is a `less-than' predicate on the elements.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 Keywords supported: :key"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 (or (listp cl-seq1) (setq cl-seq1 (append cl-seq1 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 (or (listp cl-seq2) (setq cl-seq2 (append cl-seq2 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 (cl-parsing-keywords (:key) ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 (let ((cl-res nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 (while (and cl-seq1 cl-seq2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 (if (funcall cl-pred (cl-check-key (car cl-seq2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 (cl-check-key (car cl-seq1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 (cl-push (cl-pop cl-seq2) cl-res)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 (cl-push (cl-pop cl-seq1) cl-res)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 (coerce (nconc (nreverse cl-res) cl-seq1 cl-seq2) cl-type))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 ;;; See compiler macro in cl-macs.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 (defun member* (cl-item cl-list &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 "Find the first occurrence of ITEM in LIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 Return the sublist of LIST whose car is ITEM.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 Keywords supported: :test :test-not :key"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 (if cl-keys
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 (cl-parsing-keywords (:test :test-not :key :if :if-not) ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 (while (and cl-list (not (cl-check-test cl-item (car cl-list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 (setq cl-list (cdr cl-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 cl-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 (if (and (numberp cl-item) (not (integerp cl-item)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 (member cl-item cl-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 (memq cl-item cl-list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 (defun member-if (cl-pred cl-list &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 "Find the first item satisfying PREDICATE in LIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 Return the sublist of LIST whose car matches.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 Keywords supported: :key"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 (apply 'member* nil cl-list ':if cl-pred cl-keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 (defun member-if-not (cl-pred cl-list &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 "Find the first item not satisfying PREDICATE in LIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 Return the sublist of LIST whose car matches.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 Keywords supported: :key"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 (apply 'member* nil cl-list ':if-not cl-pred cl-keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 (defun cl-adjoin (cl-item cl-list &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 (if (cl-parsing-keywords (:key) t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 (apply 'member* (cl-check-key cl-item) cl-list cl-keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 cl-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 (cons cl-item cl-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 ;;; See compiler macro in cl-macs.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 (defun assoc* (cl-item cl-alist &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 "Find the first item whose car matches ITEM in LIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 Keywords supported: :test :test-not :key"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 (if cl-keys
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 (cl-parsing-keywords (:test :test-not :key :if :if-not) ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 (while (and cl-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 (or (not (consp (car cl-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 (not (cl-check-test cl-item (car (car cl-alist))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 (setq cl-alist (cdr cl-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 (and cl-alist (car cl-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 (if (and (numberp cl-item) (not (integerp cl-item)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 (assoc cl-item cl-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 (assq cl-item cl-alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 (defun assoc-if (cl-pred cl-list &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 "Find the first item whose car satisfies PREDICATE in LIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 Keywords supported: :key"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 (apply 'assoc* nil cl-list ':if cl-pred cl-keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 (defun assoc-if-not (cl-pred cl-list &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 "Find the first item whose car does not satisfy PREDICATE in LIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 Keywords supported: :key"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 (apply 'assoc* nil cl-list ':if-not cl-pred cl-keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 (defun rassoc* (cl-item cl-alist &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 "Find the first item whose cdr matches ITEM in LIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 Keywords supported: :test :test-not :key"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 (if (or cl-keys (numberp cl-item))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 (cl-parsing-keywords (:test :test-not :key :if :if-not) ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 (while (and cl-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 (or (not (consp (car cl-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 (not (cl-check-test cl-item (cdr (car cl-alist))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 (setq cl-alist (cdr cl-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 (and cl-alist (car cl-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 (rassq cl-item cl-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 (defun rassoc-if (cl-pred cl-list &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 "Find the first item whose cdr satisfies PREDICATE in LIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 Keywords supported: :key"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 (apply 'rassoc* nil cl-list ':if cl-pred cl-keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 (defun rassoc-if-not (cl-pred cl-list &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 "Find the first item whose cdr does not satisfy PREDICATE in LIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 Keywords supported: :key"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 (apply 'rassoc* nil cl-list ':if-not cl-pred cl-keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 (defun union (cl-list1 cl-list2 &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 "Combine LIST1 and LIST2 using a set-union operation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 The result list contains all items that appear in either LIST1 or LIST2.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 This is a non-destructive function; it makes a copy of the data if necessary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 to avoid corrupting the original LIST1 and LIST2.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 Keywords supported: :test :test-not :key"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 (cond ((null cl-list1) cl-list2) ((null cl-list2) cl-list1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 ((equal cl-list1 cl-list2) cl-list1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 (or (>= (length cl-list1) (length cl-list2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 (setq cl-list1 (prog1 cl-list2 (setq cl-list2 cl-list1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 (while cl-list2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 (if (or cl-keys (numberp (car cl-list2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 (setq cl-list1 (apply 'adjoin (car cl-list2) cl-list1 cl-keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 (or (memq (car cl-list2) cl-list1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 (cl-push (car cl-list2) cl-list1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 (cl-pop cl-list2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 cl-list1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 (defun nunion (cl-list1 cl-list2 &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 "Combine LIST1 and LIST2 using a set-union operation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 The result list contains all items that appear in either LIST1 or LIST2.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 This is a destructive function; it reuses the storage of LIST1 and LIST2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 whenever possible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 Keywords supported: :test :test-not :key"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 (cond ((null cl-list1) cl-list2) ((null cl-list2) cl-list1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 (t (apply 'union cl-list1 cl-list2 cl-keys))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 (defun intersection (cl-list1 cl-list2 &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 "Combine LIST1 and LIST2 using a set-intersection operation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 The result list contains all items that appear in both LIST1 and LIST2.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 This is a non-destructive function; it makes a copy of the data if necessary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 to avoid corrupting the original LIST1 and LIST2.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 Keywords supported: :test :test-not :key"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 (and cl-list1 cl-list2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 (if (equal cl-list1 cl-list2) cl-list1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 (cl-parsing-keywords (:key) (:test :test-not)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 (let ((cl-res nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 (or (>= (length cl-list1) (length cl-list2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 (setq cl-list1 (prog1 cl-list2 (setq cl-list2 cl-list1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 (while cl-list2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 (if (if (or cl-keys (numberp (car cl-list2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 (apply 'member* (cl-check-key (car cl-list2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 cl-list1 cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 (memq (car cl-list2) cl-list1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 (cl-push (car cl-list2) cl-res))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 (cl-pop cl-list2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 cl-res)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 (defun nintersection (cl-list1 cl-list2 &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 "Combine LIST1 and LIST2 using a set-intersection operation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 The result list contains all items that appear in both LIST1 and LIST2.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 This is a destructive function; it reuses the storage of LIST1 and LIST2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 whenever possible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 Keywords supported: :test :test-not :key"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 (and cl-list1 cl-list2 (apply 'intersection cl-list1 cl-list2 cl-keys)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 (defun set-difference (cl-list1 cl-list2 &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 "Combine LIST1 and LIST2 using a set-difference operation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 The result list contains all items that appear in LIST1 but not LIST2.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 This is a non-destructive function; it makes a copy of the data if necessary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 to avoid corrupting the original LIST1 and LIST2.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 Keywords supported: :test :test-not :key"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 (if (or (null cl-list1) (null cl-list2)) cl-list1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 (cl-parsing-keywords (:key) (:test :test-not)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 (let ((cl-res nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 (while cl-list1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 (or (if (or cl-keys (numberp (car cl-list1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 (apply 'member* (cl-check-key (car cl-list1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 cl-list2 cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 (memq (car cl-list1) cl-list2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 (cl-push (car cl-list1) cl-res))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 (cl-pop cl-list1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 cl-res))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 (defun nset-difference (cl-list1 cl-list2 &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 "Combine LIST1 and LIST2 using a set-difference operation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 The result list contains all items that appear in LIST1 but not LIST2.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 This is a destructive function; it reuses the storage of LIST1 and LIST2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 whenever possible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 Keywords supported: :test :test-not :key"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 (if (or (null cl-list1) (null cl-list2)) cl-list1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 (apply 'set-difference cl-list1 cl-list2 cl-keys)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 (defun set-exclusive-or (cl-list1 cl-list2 &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 "Combine LIST1 and LIST2 using a set-exclusive-or operation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 The result list contains all items that appear in exactly one of LIST1, LIST2.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 This is a non-destructive function; it makes a copy of the data if necessary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 to avoid corrupting the original LIST1 and LIST2.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 Keywords supported: :test :test-not :key"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 (cond ((null cl-list1) cl-list2) ((null cl-list2) cl-list1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 ((equal cl-list1 cl-list2) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 (t (append (apply 'set-difference cl-list1 cl-list2 cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 (apply 'set-difference cl-list2 cl-list1 cl-keys)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 (defun nset-exclusive-or (cl-list1 cl-list2 &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 "Combine LIST1 and LIST2 using a set-exclusive-or operation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 The result list contains all items that appear in exactly one of LIST1, LIST2.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 This is a destructive function; it reuses the storage of LIST1 and LIST2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 whenever possible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 Keywords supported: :test :test-not :key"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 (cond ((null cl-list1) cl-list2) ((null cl-list2) cl-list1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 ((equal cl-list1 cl-list2) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 (t (nconc (apply 'nset-difference cl-list1 cl-list2 cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 (apply 'nset-difference cl-list2 cl-list1 cl-keys)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 (defun subsetp (cl-list1 cl-list2 &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 "True if LIST1 is a subset of LIST2.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 I.e., if every element of LIST1 also appears in LIST2.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 Keywords supported: :test :test-not :key"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 (cond ((null cl-list1) t) ((null cl-list2) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 ((equal cl-list1 cl-list2) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 (t (cl-parsing-keywords (:key) (:test :test-not)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 (while (and cl-list1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 (apply 'member* (cl-check-key (car cl-list1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 cl-list2 cl-keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 (cl-pop cl-list1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 (null cl-list1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 (defun subst-if (cl-new cl-pred cl-tree &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 "Substitute NEW for elements matching PREDICATE in TREE (non-destructively).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 Return a copy of TREE with all matching elements replaced by NEW.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 Keywords supported: :key"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 (apply 'sublis (list (cons nil cl-new)) cl-tree ':if cl-pred cl-keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 (defun subst-if-not (cl-new cl-pred cl-tree &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 "Substitute NEW for elts not matching PREDICATE in TREE (non-destructively).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 Return a copy of TREE with all non-matching elements replaced by NEW.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 Keywords supported: :key"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 (apply 'sublis (list (cons nil cl-new)) cl-tree ':if-not cl-pred cl-keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 (defun nsubst (cl-new cl-old cl-tree &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 "Substitute NEW for OLD everywhere in TREE (destructively).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 Any element of TREE which is `eql' to OLD is changed to NEW (via a call
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 to `setcar').
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 Keywords supported: :test :test-not :key"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 (apply 'nsublis (list (cons cl-old cl-new)) cl-tree cl-keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 (defun nsubst-if (cl-new cl-pred cl-tree &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 "Substitute NEW for elements matching PREDICATE in TREE (destructively).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 Any element of TREE which matches is changed to NEW (via a call to `setcar').
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 Keywords supported: :key"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 (apply 'nsublis (list (cons nil cl-new)) cl-tree ':if cl-pred cl-keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 (defun nsubst-if-not (cl-new cl-pred cl-tree &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 "Substitute NEW for elements not matching PREDICATE in TREE (destructively).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 Any element of TREE which matches is changed to NEW (via a call to `setcar').
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 Keywords supported: :key"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 (apply 'nsublis (list (cons nil cl-new)) cl-tree ':if-not cl-pred cl-keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 (defun sublis (cl-alist cl-tree &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 "Perform substitutions indicated by ALIST in TREE (non-destructively).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 Return a copy of TREE with all matching elements replaced.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 Keywords supported: :test :test-not :key"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 (cl-parsing-keywords (:test :test-not :key :if :if-not) ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 (cl-sublis-rec cl-tree)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 (defvar cl-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 (defun cl-sublis-rec (cl-tree) ; uses cl-alist/key/test*/if*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 (let ((cl-temp (cl-check-key cl-tree)) (cl-p cl-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 (while (and cl-p (not (cl-check-test-nokey (car (car cl-p)) cl-temp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 (setq cl-p (cdr cl-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 (if cl-p (cdr (car cl-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 (if (consp cl-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 (let ((cl-a (cl-sublis-rec (car cl-tree)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 (cl-d (cl-sublis-rec (cdr cl-tree))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 (if (and (eq cl-a (car cl-tree)) (eq cl-d (cdr cl-tree)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 cl-tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 (cons cl-a cl-d)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 cl-tree))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 (defun nsublis (cl-alist cl-tree &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 "Perform substitutions indicated by ALIST in TREE (destructively).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 Any matching element of TREE is changed via a call to `setcar'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 Keywords supported: :test :test-not :key"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 (cl-parsing-keywords (:test :test-not :key :if :if-not) ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 (let ((cl-hold (list cl-tree)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 (cl-nsublis-rec cl-hold)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 (car cl-hold))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 (defun cl-nsublis-rec (cl-tree) ; uses cl-alist/temp/p/key/test*/if*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 (while (consp cl-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 (let ((cl-temp (cl-check-key (car cl-tree))) (cl-p cl-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 (while (and cl-p (not (cl-check-test-nokey (car (car cl-p)) cl-temp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 (setq cl-p (cdr cl-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 (if cl-p (setcar cl-tree (cdr (car cl-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 (if (consp (car cl-tree)) (cl-nsublis-rec (car cl-tree))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 (setq cl-temp (cl-check-key (cdr cl-tree)) cl-p cl-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 (while (and cl-p (not (cl-check-test-nokey (car (car cl-p)) cl-temp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 (setq cl-p (cdr cl-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 (if cl-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 (progn (setcdr cl-tree (cdr (car cl-p))) (setq cl-tree nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 (setq cl-tree (cdr cl-tree))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 (defun tree-equal (cl-x cl-y &rest cl-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 "T if trees X and Y have `eql' leaves.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 Atoms are compared by `eql'; cons cells are compared recursively.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 Keywords supported: :test :test-not :key"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 (cl-parsing-keywords (:test :test-not :key) ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 (cl-tree-equal-rec cl-x cl-y)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 (defun cl-tree-equal-rec (cl-x cl-y)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 (while (and (consp cl-x) (consp cl-y)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 (cl-tree-equal-rec (car cl-x) (car cl-y)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 (setq cl-x (cdr cl-x) cl-y (cdr cl-y)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 (and (not (consp cl-x)) (not (consp cl-y)) (cl-check-match cl-x cl-y)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 (run-hooks 'cl-seq-load-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 ;;; cl-seq.el ends here