annotate lisp/cl-seq.el @ 5940:c608d4b0b75e cygwin64 tip

rescue lost branch from 64bit.backup
author Henry Thompson <ht@markup.co.uk>
date Thu, 16 Dec 2021 18:48:58 +0000
parents 0af042a0c116
children
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 (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
58 "Remove all items satisfying PREDICATE in SEQUENCE.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
60 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
61 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
62 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
63 SEQUENCE itself is returned, unmodified.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
65 See `remove*' for the meaning of the keywords.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
67 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
68 (apply 'remove* 'remove* cl-seq :if cl-predicate cl-keys))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
70 (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
71 "Remove all items not satisfying PREDICATE in SEQUENCE.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
73 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
74 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
75 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
76
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
77 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
78
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
79 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
80 (apply 'remove* 'remove* cl-seq :if-not cl-predicate cl-keys))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
82 (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
83 "Remove all items satisfying PREDICATE in SEQUENCE.
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 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
86 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
87 copy is always returned.
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
88
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
89 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
90
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
91 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
92 (apply 'delete* 'delete* cl-seq :if cl-predicate cl-keys))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
94 (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
95 "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
96
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
97 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
98 possible.
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
99
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
100 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
101
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
102 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
103 (apply 'delete* 'delete* cl-seq :if-not cl-predicate cl-keys))
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 (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
106 "Substitute NEW for all items satisfying PREDICATE in SEQUENCE.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
108 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
109 to avoid corrupting the original SEQUENCE.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
111 See `remove*' for the meaning of the keywords.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
113 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
114 (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
115
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
116 (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
117 "Substitute NEW for all items not satisfying PREDICATE in SEQUENCE.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
119 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
120 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
121
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
122 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
123
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
124 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
125 (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
126 cl-keys))
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 (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
129 "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
130
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
131 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
132 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
133
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
134 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
135
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
136 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
137 (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
138 cl-keys))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
140 (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
141 "Substitute NEW for all items not satisfying PREDICATE in SEQUENCE.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
143 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
144 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
145
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
146 See `remove*' for the meaning of the keywords.
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 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
149 (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
150 cl-keys))
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
151
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
152 (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
153 "Find the first item satisfying PREDICATE in SEQUENCE.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
155 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
156 function by Common Lisp) if not found.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
158 See `remove*' for the meaning of the other keywords.
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 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
161 (apply 'find 'find cl-seq :if cl-predicate cl-keys))
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 (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
164 "Find the first item not satisfying PREDICATE in SEQUENCE.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
166 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
167 function by Common Lisp) if not found.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
169 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
170
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
171 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
172 (apply 'find 'find cl-seq :if-not cl-predicate cl-keys))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
174 (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
175 "Find the first item satisfying PREDICATE in SEQUENCE.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 Return the index of the matching item, or nil if not found.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
179 See `remove*' for the meaning of the keywords.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
181 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
182 (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
183
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
184 (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
185 "Find the first item not satisfying PREDICATE in SEQUENCE.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
187 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
188
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.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190
5327
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)"
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
192 (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
193
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
194 (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
195 "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
196
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
197 See `remove*' for the meaning of the keywords.
428
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 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
200 (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
201
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
202 (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
203 "Count the number of items not satisfying PREDICATE in SEQUENCE.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
205 See `remove*' for the meaning of the keywords.
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 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
208 (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
209
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
210 (defun stable-sort (cl-seq cl-predicate &rest cl-keys)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 "Sort the argument SEQUENCE stably according to PREDICATE.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 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
213 Keywords supported: :key
545ec923b4eb add documentation on keywords to cl*.el
Ben Wing <ben@xemacs.org>
parents: 4885
diff changeset
214 :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
215 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
216 `member*' for more information.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
218 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
219 (apply 'sort* cl-seq cl-predicate cl-keys))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
221 (defun member-if (cl-predicate cl-list &rest cl-keys)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 "Find the first item satisfying PREDICATE in LIST.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 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
224 See `member*' for the meaning of :key.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
226 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
227 (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
228
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
229 (defun member-if-not (cl-predicate cl-list &rest cl-keys)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 "Find the first item not satisfying PREDICATE in LIST.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 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
232 See `member*' for the meaning of :key.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
234 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
235 (apply 'member* 'member* cl-list :if-not cl-predicate cl-keys))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
237 (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
238 "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
239 See `member*' for the meaning of :key.
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 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
242 (apply 'assoc* 'assoc* cl-alist :if cl-predicate cl-keys))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
244 (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
245 "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
246 See `member*' for the meaning of :key.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
248 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
249 (apply 'assoc* 'assoc* cl-alist :if-not cl-predicate cl-keys))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
251 (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
252 "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
253 See `member*' for the meaning of :key.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
255 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
256 (apply 'rassoc* 'rassoc* cl-alist :if cl-predicate cl-keys))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
258 (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
259 "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
260 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
261
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
262 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
263 (apply 'rassoc* 'rassoc* cl-alist :if-not cl-predicate cl-keys))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264
5067
7d7ae8db0341 add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents: 5066
diff changeset
265 ;; 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
266 (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
267 "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
268 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
269 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
270 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
271 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
272 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
273
5067
7d7ae8db0341 add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents: 5066
diff changeset
274 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
275 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
276
5067
7d7ae8db0341 add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents: 5066
diff changeset
277 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
278
7d7ae8db0341 add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents: 5066
diff changeset
279 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
280 extension.
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: (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
283 ;; 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
284 ;; 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
285 ;; 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
286 ;; `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
287 ;; 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
288 ;; semantics of `union'.
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
289 (apply 'union cl-list1 cl-list2 :stable t cl-keys))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290
5067
7d7ae8db0341 add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents: 5066
diff changeset
291 ;; 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
292 (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
293 "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
294
5067
7d7ae8db0341 add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents: 5066
diff changeset
295 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
296 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
297 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
298
5067
7d7ae8db0341 add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents: 5066
diff changeset
299 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
300 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
301
5067
7d7ae8db0341 add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents: 5066
diff changeset
302 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
303
7d7ae8db0341 add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents: 5066
diff changeset
304 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
305 extension.
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
306
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
307 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
308 ;; 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
309 ;; 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
310 ;; 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
311 ;; `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
312 ;; 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
313 ;; 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
314 (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
315
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
316 (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
317 "Substitute NEW for elements matching PREDICATE in TREE (non-destructively).
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
319 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
320 element matches PREDICATE, return tree.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
322 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
323
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
324 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
325 (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
326
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
327 (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
328 "Substitute NEW for elements not matching PREDICATE in TREE.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
330 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
331 element matches PREDICATE, return tree.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
333 See `member*' for the meaning of :key.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
335 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
336 (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
337
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
338 (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
339 "Substitute NEW for elements matching PREDICATE in TREE (destructively).
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 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
342
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
343 See `member*' for the meaning of :key.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
345 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
346 (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
347
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
348 (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
349 "Substitute NEW for elements not matching PREDICATE in TREE (destructively).
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350
5327
d1b17a33450b Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5261
diff changeset
351 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
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 '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
357
2153
393039450288 [xemacs-hg @ 2004-06-26 21:25:23 by james]
james
parents: 613
diff changeset
358 ;;; arch-tag: ec1cc072-9006-4225-b6ba-d6b07ed1710c
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 ;;; cl-seq.el ends here