Mercurial > hg > xemacs-beta
annotate lisp/cl-seq.el @ 5398:5256fedd50e6
issue 757 - tty device metric for num-color-cells
-------------------- ChangeLog entries follow: --------------------
src/ChangeLog addition:
2011-03-28 Jeff Sparkes <jsparkes@gmail.com>
* console-tty-impl.h (struct tty_console): Add field for number of
displayable colors.
* device-tty.c (tty_device_system_metrics): Return metrics for
num-color-cells and num-bit-planes. Tracker issue 757.
* device.c: There are two required args for device-system-metric.
* redisplay-tty.c (init_tty_for_redisplay): Retrieve number of
colors from terminal description. Default to 2 if none found.
author | Jeff Sparkes <jsparkes@gmail.com> |
---|---|
date | Mon, 28 Mar 2011 09:25:15 -0400 |
parents | b4ef3128160c |
children | 0af042a0c116 |
rev | line source |
---|---|
613 | 1 ;;; cl-seq.el --- Common Lisp extensions for XEmacs Lisp (part three) |
428 | 2 |
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 | 5 |
6 ;; Author: Dave Gillespie <daveg@synaptics.com> | |
7 ;; Maintainer: XEmacs Development Team | |
8 ;; Version: 2.02 | |
9 ;; Keywords: extensions, dumped | |
10 | |
11 ;; This file is part of XEmacs. | |
12 | |
13 ;; XEmacs is free software; you can redistribute it and/or modify it | |
14 ;; under the terms of the GNU General Public License as published by | |
15 ;; the Free Software Foundation; either version 2, or (at your option) | |
16 ;; any later version. | |
17 | |
18 ;; XEmacs is distributed in the hope that it will be useful, but | |
19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
21 ;; General Public License for more details. | |
22 | |
23 ;; You should have received a copy of the GNU General Public License | |
24 ;; along with XEmacs; see the file COPYING. If not, write to the Free | |
25 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
26 ;; 02111-1307, USA. | |
27 | |
2153 | 28 ;;; Synched up with: FSF 21.3. |
428 | 29 |
30 ;;; Commentary: | |
31 | |
32 ;; This file is dumped with XEmacs. | |
33 | |
34 ;; These are extensions to Emacs Lisp that provide a degree of | |
35 ;; Common Lisp compatibility, beyond what is already built-in | |
36 ;; in Emacs Lisp. | |
37 ;; | |
38 ;; This package was written by Dave Gillespie; it is a complete | |
39 ;; rewrite of Cesar Quiroz's original cl.el package of December 1986. | |
40 ;; | |
41 ;; This package works with Emacs 18, Emacs 19, and Lucid Emacs 19. | |
42 ;; | |
43 ;; Bug reports, comments, and suggestions are welcome! | |
44 | |
45 ;; This file contains the Common Lisp sequence and list functions | |
46 ;; which take keyword arguments. | |
47 | |
48 ;; See cl.el for Change Log. | |
49 | |
50 ;;; Code: | |
51 | |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
52 ;; 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
|
53 ;; 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
|
54 ;; 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
|
55 ;; () 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
|
56 ;; 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
|
57 ;; user-supplied test predicate may well interfere with each other). |
428 | 58 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
59 (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
|
60 "Remove all items satisfying PREDICATE in SEQUENCE. |
428 | 61 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
62 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
|
63 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
|
64 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
|
65 SEQUENCE itself is returned, unmodified. |
428 | 66 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
67 See `remove*' for the meaning of the keywords. |
428 | 68 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
69 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
|
70 (apply 'remove* 'remove* cl-seq :if cl-predicate cl-keys)) |
428 | 71 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
72 (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
|
73 "Remove all items not satisfying PREDICATE in SEQUENCE. |
428 | 74 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
75 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
|
76 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
|
77 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
|
78 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
79 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
|
80 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
81 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
|
82 (apply 'remove* 'remove* cl-seq :if-not cl-predicate cl-keys)) |
428 | 83 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
84 (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
|
85 "Remove all items satisfying PREDICATE in SEQUENCE. |
428 | 86 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
87 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
|
88 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
|
89 copy is always returned. |
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 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
|
92 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
93 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
|
94 (apply 'delete* 'delete* cl-seq :if cl-predicate cl-keys)) |
428 | 95 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
96 (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
|
97 "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
|
98 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
99 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
|
100 possible. |
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 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
|
103 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
104 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
|
105 (apply 'delete* 'delete* cl-seq :if-not cl-predicate cl-keys)) |
428 | 106 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
107 (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
|
108 "Substitute NEW for all items satisfying PREDICATE in SEQUENCE. |
428 | 109 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
110 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
|
111 to avoid corrupting the original SEQUENCE. |
428 | 112 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
113 See `remove*' for the meaning of the keywords. |
428 | 114 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
115 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
|
116 (apply 'substitute cl-new 'substitute cl-seq :if cl-predicate cl-keys)) |
428 | 117 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
118 (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
|
119 "Substitute NEW for all items not satisfying PREDICATE in SEQUENCE. |
428 | 120 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
121 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
|
122 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
|
123 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
124 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
|
125 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
126 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
|
127 (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
|
128 cl-keys)) |
428 | 129 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
130 (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
|
131 "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
|
132 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
133 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
|
134 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
|
135 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
136 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
|
137 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
138 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
|
139 (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
|
140 cl-keys)) |
428 | 141 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
142 (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
|
143 "Substitute NEW for all items not satisfying PREDICATE in SEQUENCE. |
428 | 144 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
145 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
|
146 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
|
147 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
148 See `remove*' for the meaning of the keywords. |
428 | 149 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
150 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
|
151 (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
|
152 cl-keys)) |
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 (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
|
155 "Find the first item satisfying PREDICATE in SEQUENCE. |
428 | 156 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
157 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
|
158 function by Common Lisp) if not found. |
428 | 159 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
160 See `remove*' for the meaning of the other keywords. |
428 | 161 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
162 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
|
163 (apply 'find 'find cl-seq :if cl-predicate cl-keys)) |
428 | 164 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
165 (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
|
166 "Find the first item not satisfying PREDICATE in SEQUENCE. |
428 | 167 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
168 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
|
169 function by Common Lisp) if not found. |
428 | 170 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
171 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
|
172 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
173 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
|
174 (apply 'find 'find cl-seq :if-not cl-predicate cl-keys)) |
428 | 175 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
176 (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
|
177 "Find the first item satisfying PREDICATE in SEQUENCE. |
428 | 178 |
179 Return the index of the matching item, or nil if not found. | |
180 | |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
181 See `remove*' for the meaning of the keywords. |
428 | 182 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
183 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
|
184 (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
|
185 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
186 (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
|
187 "Find the first item not satisfying PREDICATE in SEQUENCE. |
428 | 188 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
189 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
|
190 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
191 See `remove*' for the meaning of the keywords. |
428 | 192 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
193 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
|
194 (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
|
195 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
196 (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
|
197 "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
|
198 |
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 | 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 '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
|
203 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
204 (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
|
205 "Count the number of items not satisfying PREDICATE in SEQUENCE. |
428 | 206 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
207 See `remove*' for the meaning of the keywords. |
428 | 208 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
209 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
|
210 (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
|
211 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
212 (defun stable-sort (cl-seq cl-predicate &rest cl-keys) |
428 | 213 "Sort the argument SEQUENCE stably according to PREDICATE. |
214 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
|
215 Keywords supported: :key |
545ec923b4eb
add documentation on keywords to cl*.el
Ben Wing <ben@xemacs.org>
parents:
4885
diff
changeset
|
216 :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
|
217 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
|
218 `member*' for more information. |
428 | 219 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
220 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
|
221 (apply 'sort* cl-seq cl-predicate cl-keys)) |
428 | 222 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
223 (defun member-if (cl-predicate cl-list &rest cl-keys) |
428 | 224 "Find the first item satisfying PREDICATE in LIST. |
225 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
|
226 See `member*' for the meaning of :key. |
428 | 227 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
228 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
|
229 (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
|
230 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
231 (defun member-if-not (cl-predicate cl-list &rest cl-keys) |
428 | 232 "Find the first item not satisfying PREDICATE in LIST. |
233 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
|
234 See `member*' for the meaning of :key. |
428 | 235 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
236 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
|
237 (apply 'member* 'member* cl-list :if-not cl-predicate cl-keys)) |
428 | 238 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
239 (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
|
240 "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
|
241 See `member*' for the meaning of :key. |
428 | 242 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
243 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
|
244 (apply 'assoc* 'assoc* cl-alist :if cl-predicate cl-keys)) |
428 | 245 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
246 (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
|
247 "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
|
248 See `member*' for the meaning of :key. |
428 | 249 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
250 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
|
251 (apply 'assoc* 'assoc* cl-alist :if-not cl-predicate cl-keys)) |
428 | 252 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
253 (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
|
254 "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
|
255 See `member*' for the meaning of :key. |
428 | 256 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
257 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
|
258 (apply 'rassoc* 'rassoc* cl-alist :if cl-predicate cl-keys)) |
428 | 259 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
260 (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
|
261 "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
|
262 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
|
263 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
264 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
|
265 (apply 'rassoc* 'rassoc* cl-alist :if-not cl-predicate cl-keys)) |
428 | 266 |
5067
7d7ae8db0341
add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents:
5066
diff
changeset
|
267 ;; 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
|
268 (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
|
269 "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
|
270 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
|
271 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
|
272 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
|
273 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
|
274 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
|
275 |
5067
7d7ae8db0341
add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents:
5066
diff
changeset
|
276 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
|
277 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
|
278 |
5067
7d7ae8db0341
add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents:
5066
diff
changeset
|
279 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
|
280 |
7d7ae8db0341
add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents:
5066
diff
changeset
|
281 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
|
282 extension. |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
283 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
284 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
|
285 ;; 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
|
286 ;; 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
|
287 ;; 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
|
288 ;; `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
|
289 ;; 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
|
290 ;; semantics of `union'. |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
291 (apply 'union cl-list1 cl-list2 :stable t cl-keys)) |
428 | 292 |
5067
7d7ae8db0341
add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents:
5066
diff
changeset
|
293 ;; 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
|
294 (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
|
295 "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
|
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 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
|
298 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
|
299 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
|
300 |
5067
7d7ae8db0341
add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents:
5066
diff
changeset
|
301 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
|
302 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
|
303 |
5067
7d7ae8db0341
add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents:
5066
diff
changeset
|
304 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
|
305 |
7d7ae8db0341
add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents:
5066
diff
changeset
|
306 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
|
307 extension. |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
308 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
309 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
|
310 ;; 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
|
311 ;; 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
|
312 ;; 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
|
313 ;; `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
|
314 ;; 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
|
315 ;; 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
|
316 (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
|
317 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
318 (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
|
319 "Substitute NEW for elements matching PREDICATE in TREE (non-destructively). |
428 | 320 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
321 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
|
322 element matches PREDICATE, return tree. |
428 | 323 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
324 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
|
325 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
326 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
|
327 (apply 'subst cl-new 'subst cl-tree :if cl-predicate cl-keys)) |
428 | 328 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
329 (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
|
330 "Substitute NEW for elements not matching PREDICATE in TREE. |
428 | 331 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
332 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
|
333 element matches PREDICATE, return tree. |
428 | 334 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
335 See `member*' for the meaning of :key. |
428 | 336 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
337 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
|
338 (apply 'subst cl-new 'subst cl-tree :if-not cl-predicate cl-keys)) |
428 | 339 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
340 (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
|
341 "Substitute NEW for elements matching PREDICATE in TREE (destructively). |
428 | 342 |
343 Any element of TREE which matches is changed to NEW (via a call to `setcar'). | |
344 | |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
345 See `member*' for the meaning of :key. |
428 | 346 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
347 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
|
348 (apply 'nsubst cl-new 'nsubst cl-tree :if cl-predicate cl-keys)) |
428 | 349 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
350 (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
|
351 "Substitute NEW for elements not matching PREDICATE in TREE (destructively). |
428 | 352 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
353 Any element of TREE which matches is changed to NEW (via a call to `setcar'). |
428 | 354 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
355 See `member*' for the meaning of :key. |
428 | 356 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
357 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
|
358 (apply 'nsubst cl-new 'nsubst cl-tree :if-not cl-predicate cl-keys)) |
428 | 359 |
2153 | 360 ;;; arch-tag: ec1cc072-9006-4225-b6ba-d6b07ed1710c |
428 | 361 ;;; cl-seq.el ends here |