annotate lisp/cl-seq.el @ 5451:10cd76b594a5

License comment terminated.
author Mats Lidell <matsl@xemacs.org>
date Fri, 07 Jan 2011 23:31:56 +0100
parents 89331fa1c819
children 0af042a0c116
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 442
diff changeset
1 ;;; cl-seq.el --- Common Lisp extensions for XEmacs Lisp (part three)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 ;; Copyright (C) 1993 Free Software Foundation, Inc.
5066
545ec923b4eb add documentation on keywords to cl*.el
Ben Wing <ben@xemacs.org>
parents: 4885
diff changeset
4 ;; Copyright (C) 2010 Ben Wing.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 ;; Author: Dave Gillespie <daveg@synaptics.com>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 ;; Maintainer: XEmacs Development Team
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 ;; Version: 2.02
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 ;; Keywords: extensions, dumped
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 ;; This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5261
diff changeset
13 ;; XEmacs is free software: you can redistribute it and/or modify it
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5261
diff changeset
14 ;; under the terms of the GNU General Public License as published by the
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5261
diff changeset
15 ;; Free Software Foundation, either version 3 of the License, or (at your
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5261
diff changeset
16 ;; option) any later version.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5261
diff changeset
18 ;; XEmacs is distributed in the hope that it will be useful, but WITHOUT
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5261
diff changeset
19 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5261
diff changeset
20 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5261
diff changeset
21 ;; for more details.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5261
diff changeset
24 ;; along with XEmacs. If not, see <http://www.gnu.org/licenses/>.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25
2153
393039450288 [xemacs-hg @ 2004-06-26 21:25:23 by james]
james
parents: 613
diff changeset
26 ;;; Synched up with: FSF 21.3.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 ;;; Commentary:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 ;; This file is dumped with XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 ;; These are extensions to Emacs Lisp that provide a degree of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 ;; Common Lisp compatibility, beyond what is already built-in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 ;; in Emacs Lisp.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 ;; This package was written by Dave Gillespie; it is a complete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 ;; rewrite of Cesar Quiroz's original cl.el package of December 1986.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 ;; This package works with Emacs 18, Emacs 19, and Lucid Emacs 19.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 ;; Bug reports, comments, and suggestions are welcome!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 ;; This file contains the Common Lisp sequence and list functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 ;; which take keyword arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 ;; See cl.el for Change Log.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 ;;; Code:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
50 ;; XEmacs; all the heavy lifting of this file is now in C. There's no need
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
51 ;; for the cl-parsing-keywords macro. We could use defun* for the
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
52 ;; keyword-parsing code, which would avoid the necessity of the arguments:
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
53 ;; () lists in the docstrings, but that often breaks because of dynamic
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
54 ;; scope (e.g. a variable called start bound in this file and one in a
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
55 ;; user-supplied test predicate may well interfere with each other).
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
57 ;; XEmacs change: these two are in subr.el in GNU Emacs.
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
58 (defun remove (cl-item cl-seq)
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
59 "Remove all occurrences of ITEM in SEQUENCE, testing with `equal'.
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
60
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
61 This is a non-destructive function; it makes a copy of SEQUENCE if necessary
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
62 to avoid corrupting the original SEQUENCE.
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
63 Also see: `remove*', `delete', `delete*'
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
64
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
65 arguments: (ITEM SEQUENCE)"
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
66 (remove* cl-item cl-seq :test #'equal))
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
67
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
68 (defun remq (cl-item cl-seq)
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
69 "Remove all occurrences of ITEM in SEQUENCE, comparing with `eq'.
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
70
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
71 This is a non-destructive function; it makes a copy of SEQUENCE to avoid
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
72 corrupting the original LIST. See also the more general `remove*'.
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
73
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
74 arguments: (ITEM SEQUENCE)"
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
75 (remove* cl-item cl-seq :test #'eq))
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
76
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
77 (defun remove-if (cl-predicate cl-seq &rest cl-keys)
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
78 "Remove all items satisfying PREDICATE in SEQUENCE.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
80 This is a non-destructive function; it makes a copy of SEQUENCE if necessary
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
81 to avoid corrupting the original SEQUENCE. If SEQUENCE is a list, the copy
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
82 may share list structure with SEQUENCE. If no item satisfies PREDICATE,
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
83 SEQUENCE itself is returned, unmodified.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
85 See `remove*' for the meaning of the keywords.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
87 arguments: (PREDICATE SEQUENCE &key (KEY #'IDENTITY) (START 0) END FROM-END COUNT)"
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
88 (apply 'remove* 'remove* cl-seq :if cl-predicate cl-keys))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
90 (defun remove-if-not (cl-predicate cl-seq &rest cl-keys)
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
91 "Remove all items not satisfying PREDICATE in SEQUENCE.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
93 This is a non-destructive function; it makes a copy of SEQUENCE if necessary
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
94 to avoid corrupting the original SEQUENCE. If SEQUENCE is a list, the copy
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
95 may share list structure with SEQUENCE.
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
96
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
97 See `remove*' for the meaning of the keywords.
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
98
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
99 arguments: (PREDICATE SEQUENCE &key (KEY #'IDENTITY) (START 0) END FROM-END COUNT)"
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
100 (apply 'remove* 'remove* cl-seq :if-not cl-predicate cl-keys))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
102 (defun delete-if (cl-predicate cl-seq &rest cl-keys)
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
103 "Remove all items satisfying PREDICATE in SEQUENCE.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
105 This is a destructive function; if SEQUENCE is a list, it reuses its
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
106 storage. If SEQUENCE is an array and some element satisfies SEQUENCE, a
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
107 copy is always returned.
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
108
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
109 See `remove*' for the meaning of the keywords.
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
110
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
111 arguments: (PREDICATE SEQUENCE &key (KEY #'IDENTITY) (START 0) END FROM-END COUNT)"
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
112 (apply 'delete* 'delete* cl-seq :if cl-predicate cl-keys))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
114 (defun delete-if-not (cl-predicate cl-seq &rest cl-keys)
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
115 "Remove all items not satisfying PREDICATE in SEQUENCE.
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
116
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
117 This is a destructive function; it reuses the storage of SEQUENCE whenever
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
118 possible.
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
119
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
120 See `remove*' for the meaning of the keywords.
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
121
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
122 arguments: (PREDICATE SEQUENCE &key (KEY #'IDENTITY) (START 0) END FROM-END COUNT)"
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
123 (apply 'delete* 'delete* cl-seq :if-not cl-predicate cl-keys))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
125 (defun substitute-if (cl-new cl-predicate cl-seq &rest cl-keys)
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
126 "Substitute NEW for all items satisfying PREDICATE in SEQUENCE.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
128 This is a non-destructive function; it makes a copy of SEQUENCE if necessary
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
129 to avoid corrupting the original SEQUENCE.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
131 See `remove*' for the meaning of the keywords.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
133 arguments: (NEW PREDICATE SEQUENCE &key (KEY #'identity) (START 0) END COUNT FROM-END)"
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
134 (apply 'substitute cl-new 'substitute cl-seq :if cl-predicate cl-keys))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
136 (defun substitute-if-not (cl-new cl-predicate cl-seq &rest cl-keys)
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
137 "Substitute NEW for all items not satisfying PREDICATE in SEQUENCE.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
139 This is a non-destructive function; it makes a copy of SEQUENCE if necessary
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
140 to avoid corrupting the original SEQUENCE.
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
141
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
142 See `remove*' for the meaning of the keywords.
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
143
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
144 arguments: (NEW PREDICATE SEQUENCE &key (KEY #'identity) (START 0) END COUNT FROM-END)"
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
145 (apply 'substitute cl-new 'substitute cl-seq :if-not cl-predicate
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
146 cl-keys))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
148 (defun nsubstitute-if (cl-new cl-predicate cl-seq &rest cl-keys)
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
149 "Substitute NEW for all items satisfying PREDICATE in SEQUENCE.
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
150
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
151 This is destructive function; it modifies SEQUENCE directly, never returning
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
152 a copy. See `substitute-if' for a non-destructive version.
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
153
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
154 See `remove*' for the meaning of the keywords.
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
155
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
156 arguments: (NEW PREDICATE SEQUENCE &key (KEY #'identity) (START 0) END COUNT FROM-END)"
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
157 (apply 'nsubstitute cl-new 'nsubstitute cl-seq :if cl-predicate
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
158 cl-keys))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
160 (defun nsubstitute-if-not (cl-new cl-predicate cl-seq &rest cl-keys)
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
161 "Substitute NEW for all items not satisfying PREDICATE in SEQUENCE.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
163 This is destructive function; it modifies SEQUENCE directly, never returning
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
164 a copy. See `substitute-if-not' for a non-destructive version.
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
165
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
166 See `remove*' for the meaning of the keywords.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
168 arguments: (NEW PREDICATE SEQUENCE &key (KEY #'identity) (START 0) END COUNT FROM-END)"
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
169 (apply 'nsubstitute cl-new 'nsubstitute cl-seq :if-not cl-predicate
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
170 cl-keys))
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
171
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
172 (defun find-if (cl-predicate cl-seq &rest cl-keys)
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
173 "Find the first item satisfying PREDICATE in SEQUENCE.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
175 Return the matching item, or DEFAULT (not a keyword specified for this
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
176 function by Common Lisp) if not found.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
178 See `remove*' for the meaning of the other keywords.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
180 arguments: (PREDICATE SEQUENCE &key (KEY #'identity) (START 0) END FROM-END DEFAULT)"
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
181 (apply 'find 'find cl-seq :if cl-predicate cl-keys))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
183 (defun find-if-not (cl-predicate cl-seq &rest cl-keys)
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
184 "Find the first item not satisfying PREDICATE in SEQUENCE.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
186 Return the matching ITEM, or DEFAULT (not a keyword specified for this
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
187 function by Common Lisp) if not found.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
189 See `remove*' for the meaning of the keywords.
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
190
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
191 arguments: (PREDICATE SEQUENCE &key (KEY #'identity) (START 0) END FROM-END DEFAULT)"
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
192 (apply 'find 'find cl-seq :if-not cl-predicate cl-keys))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
194 (defun position-if (cl-predicate cl-seq &rest cl-keys)
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
195 "Find the first item satisfying PREDICATE in SEQUENCE.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 Return the index of the matching item, or nil if not found.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
199 See `remove*' for the meaning of the keywords.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
201 arguments: (PREDICATE SEQUENCE &key (KEY #'identity) (START 0) END FROM-END)"
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
202 (apply 'position 'position cl-seq :if cl-predicate cl-keys))
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
203
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
204 (defun position-if-not (cl-predicate cl-seq &rest cl-keys)
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
205 "Find the first item not satisfying PREDICATE in SEQUENCE.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
207 Return the index of the matching item, or nil if not found.
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
208
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
209 See `remove*' for the meaning of the keywords.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
211 arguments: (PREDICATE SEQUENCE &key (KEY #'identity) (START 0) END FROM-END)"
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
212 (apply 'position 'position cl-seq :if-not cl-predicate cl-keys))
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
213
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
214 (defun count-if (cl-predicate cl-seq &rest cl-keys)
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
215 "Count the number of items satisfying PREDICATE in SEQUENCE.
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
216
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
217 See `remove*' for the meaning of the keywords.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
219 arguments: (PREDICATE SEQUENCE &key (KEY #'identity) (START 0) END FROM-END)"
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
220 (apply 'count 'count cl-seq :if cl-predicate cl-keys))
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
221
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
222 (defun count-if-not (cl-predicate cl-seq &rest cl-keys)
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
223 "Count the number of items not satisfying PREDICATE in SEQUENCE.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
225 See `remove*' for the meaning of the keywords.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
227 arguments: (PREDICATE SEQUENCE &key (KEY #'identity) (START 0) END FROM-END)"
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
228 (apply 'count 'count cl-seq :if-not cl-predicate cl-keys))
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
229
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
230 (defun stable-sort (cl-seq cl-predicate &rest cl-keys)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 "Sort the argument SEQUENCE stably according to PREDICATE.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 This is a destructive function; it reuses the storage of SEQUENCE if possible.
5066
545ec923b4eb add documentation on keywords to cl*.el
Ben Wing <ben@xemacs.org>
parents: 4885
diff changeset
233 Keywords supported: :key
545ec923b4eb add documentation on keywords to cl*.el
Ben Wing <ben@xemacs.org>
parents: 4885
diff changeset
234 :key specifies a one-argument function that transforms elements of SEQUENCE
545ec923b4eb add documentation on keywords to cl*.el
Ben Wing <ben@xemacs.org>
parents: 4885
diff changeset
235 into \"comparison keys\" before the test predicate is applied. See
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5084
diff changeset
236 `member*' for more information.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
238 arguments: (SEQUENCE PREDICATE &key (KEY #'identity))"
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
239 (apply 'sort* cl-seq cl-predicate cl-keys))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
241 (defun member-if (cl-predicate cl-list &rest cl-keys)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 "Find the first item satisfying PREDICATE in LIST.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 Return the sublist of LIST whose car matches.
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
244 See `member*' for the meaning of :key.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
246 arguments: (PREDICATE LIST &key (KEY #'identity))"
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
247 (apply 'member* 'member* cl-list :if cl-predicate cl-keys))
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
248
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
249 (defun member-if-not (cl-predicate cl-list &rest cl-keys)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 "Find the first item not satisfying PREDICATE in LIST.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 Return the sublist of LIST whose car matches.
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
252 See `member*' for the meaning of :key.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
254 arguments: (PREDICATE LIST &key (KEY #'identity))"
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
255 (apply 'member* 'member* cl-list :if-not cl-predicate cl-keys))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
257 (defun assoc-if (cl-predicate cl-alist &rest cl-keys)
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
258 "Return the first item whose car satisfies PREDICATE in ALIST.
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
259 See `member*' for the meaning of :key.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
261 arguments: (PREDICATE ALIST &key (KEY #'identity))"
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
262 (apply 'assoc* 'assoc* cl-alist :if cl-predicate cl-keys))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
264 (defun assoc-if-not (cl-predicate cl-alist &rest cl-keys)
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
265 "Return the first item whose car does not satisfy PREDICATE in ALIST.
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
266 See `member*' for the meaning of :key.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
268 arguments: (PREDICATE ALIST &key (KEY #'identity))"
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
269 (apply 'assoc* 'assoc* cl-alist :if-not cl-predicate cl-keys))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
271 (defun rassoc-if (cl-predicate cl-alist &rest cl-keys)
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
272 "Return the first item whose cdr satisfies PREDICATE in ALIST.
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
273 See `member*' for the meaning of :key.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
275 arguments: (PREDICATE ALIST &key (KEY #'identity))"
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
276 (apply 'rassoc* 'rassoc* cl-alist :if cl-predicate cl-keys))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
278 (defun rassoc-if-not (cl-predicate cl-alist &rest cl-keys)
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
279 "Return the first item whose cdr does not satisfy PREDICATE in ALIST.
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
280 See `member*' for the meaning of :key.
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
281
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
282 arguments: (PREDICATE ALIST &key (KEY #'identity))"
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
283 (apply 'rassoc* 'rassoc* cl-alist :if-not cl-predicate cl-keys))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284
5067
7d7ae8db0341 add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents: 5066
diff changeset
285 ;; XEmacs addition: NOT IN COMMON LISP.
7d7ae8db0341 add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents: 5066
diff changeset
286 (defun stable-union (cl-list1 cl-list2 &rest cl-keys)
7d7ae8db0341 add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents: 5066
diff changeset
287 "Stably combine LIST1 and LIST2 using a set-union operation.
7d7ae8db0341 add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents: 5066
diff changeset
288 The result list contains all items that appear in either LIST1 or LIST2.
7d7ae8db0341 add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents: 5066
diff changeset
289 The result is \"stable\" in that it preserves the ordering of elements in
7d7ae8db0341 add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents: 5066
diff changeset
290 LIST1 and LIST2. The result specifically consists of the elements in LIST1
7d7ae8db0341 add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents: 5066
diff changeset
291 in order, followed by any elements in LIST2 that are not also in LIST1, in
7d7ae8db0341 add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents: 5066
diff changeset
292 the order given in LIST2.
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
293
5067
7d7ae8db0341 add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents: 5066
diff changeset
294 This is a non-destructive function; it makes a copy of the data if necessary
7d7ae8db0341 add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents: 5066
diff changeset
295 to avoid corrupting the original LIST1 and LIST2.
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
296
5067
7d7ae8db0341 add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents: 5066
diff changeset
297 See `union' for the meaning of :test, :test-not and :key.
7d7ae8db0341 add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents: 5066
diff changeset
298
7d7ae8db0341 add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents: 5066
diff changeset
299 NOTE: This is *NOT* a function defined by Common Lisp, but an XEmacs
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
300 extension.
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
301
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
302 arguments: (LIST1 LIST2 &key (TEST #'eql) (KEY #'identity) TEST-NOT)"
5067
7d7ae8db0341 add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents: 5066
diff changeset
303 ;; The standard `union' doesn't produce a "stable" union --
7d7ae8db0341 add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents: 5066
diff changeset
304 ;; it iterates over the second list instead of the first one, and returns
7d7ae8db0341 add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents: 5066
diff changeset
305 ;; the values in backwards order. According to the CLTL2 documentation,
7d7ae8db0341 add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents: 5066
diff changeset
306 ;; `union' is not required to preserve the ordering of elements in
7d7ae8db0341 add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents: 5066
diff changeset
307 ;; any fashion, so we add a new function rather than changing the
7d7ae8db0341 add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents: 5066
diff changeset
308 ;; semantics of `union'.
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
309 (apply 'union cl-list1 cl-list2 :stable t cl-keys))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310
5067
7d7ae8db0341 add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents: 5066
diff changeset
311 ;; XEmacs addition: NOT IN COMMON LISP.
7d7ae8db0341 add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents: 5066
diff changeset
312 (defun stable-intersection (cl-list1 cl-list2 &rest cl-keys)
7d7ae8db0341 add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents: 5066
diff changeset
313 "Stably combine LIST1 and LIST2 using a set-intersection operation.
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
314
5067
7d7ae8db0341 add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents: 5066
diff changeset
315 The result list contains all items that appear in both LIST1 and LIST2.
7d7ae8db0341 add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents: 5066
diff changeset
316 The result is \"stable\" in that it preserves the ordering of elements in
7d7ae8db0341 add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents: 5066
diff changeset
317 LIST1 that are also in LIST2.
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
318
5067
7d7ae8db0341 add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents: 5066
diff changeset
319 This is a non-destructive function; it makes a copy of the data if necessary
7d7ae8db0341 add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents: 5066
diff changeset
320 to avoid corrupting the original LIST1 and LIST2.
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
321
5067
7d7ae8db0341 add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents: 5066
diff changeset
322 See `union' for the meaning of :test, :test-not and :key.
7d7ae8db0341 add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents: 5066
diff changeset
323
7d7ae8db0341 add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents: 5066
diff changeset
324 NOTE: This is *NOT* a function defined by Common Lisp, but an XEmacs
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
325 extension.
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
326
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
327 arguments: (LIST1 LIST2 &key (TEST #'eql) (KEY #'identity) TEST-NOT)"
5067
7d7ae8db0341 add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents: 5066
diff changeset
328 ;; The standard `intersection' doesn't produce a "stable" intersection --
7d7ae8db0341 add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents: 5066
diff changeset
329 ;; it iterates over the second list instead of the first one, and returns
7d7ae8db0341 add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents: 5066
diff changeset
330 ;; the values in backwards order. According to the CLTL2 documentation,
7d7ae8db0341 add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents: 5066
diff changeset
331 ;; `intersection' is not required to preserve the ordering of elements in
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
332 ;; any fashion, but it's trivial to implement a stable ordering in C,
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
333 ;; given that the order of arguments to the test function is specified.
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
334 (apply 'intersection cl-list1 cl-list2 :stable t cl-keys))
5067
7d7ae8db0341 add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents: 5066
diff changeset
335
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
336 (defun subst-if (cl-new cl-predicate cl-tree &rest cl-keys)
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
337 "Substitute NEW for elements matching PREDICATE in TREE (non-destructively).
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
339 Return a copy of TREE with all matching elements replaced by NEW. If no
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
340 element matches PREDICATE, return tree.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
342 See `member*' for the meaning of :key.
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
343
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
344 arguments: (NEW PREDICATE TREE &key (KEY #'identity))"
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
345 (apply 'subst cl-new 'subst cl-tree :if cl-predicate cl-keys))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
347 (defun subst-if-not (cl-new cl-predicate cl-tree &rest cl-keys)
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
348 "Substitute NEW for elements not matching PREDICATE in TREE.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
350 Return a copy of TREE with all matching elements replaced by NEW. If every
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
351 element matches PREDICATE, return tree.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
353 See `member*' for the meaning of :key.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
355 arguments: (NEW PREDICATE TREE &key (KEY #'identity))"
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
356 (apply 'subst cl-new 'subst cl-tree :if-not cl-predicate cl-keys))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
358 (defun nsubst-if (cl-new cl-predicate cl-tree &rest cl-keys)
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
359 "Substitute NEW for elements matching PREDICATE in TREE (destructively).
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 Any element of TREE which matches is changed to NEW (via a call to `setcar').
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
363 See `member*' for the meaning of :key.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
365 arguments: (NEW PREDICATE TREE &key (KEY #'identity))"
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
366 (apply 'nsubst cl-new 'nsubst cl-tree :if cl-predicate cl-keys))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
368 (defun nsubst-if-not (cl-new cl-predicate cl-tree &rest cl-keys)
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
369 "Substitute NEW for elements not matching PREDICATE in TREE (destructively).
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
371 Any element of TREE which matches is changed to NEW (via a call to `setcar').
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
373 See `member*' for the meaning of :key.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
375 arguments: (NEW PREDICATE TREE &key (KEY #'identity))"
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
376 (apply 'nsubst cl-new 'nsubst cl-tree :if-not cl-predicate cl-keys))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377
2153
393039450288 [xemacs-hg @ 2004-06-26 21:25:23 by james]
james
parents: 613
diff changeset
378 ;;; arch-tag: ec1cc072-9006-4225-b6ba-d6b07ed1710c
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 ;;; cl-seq.el ends here