Mercurial > hg > xemacs-beta
annotate lisp/cl-seq.el @ 5753:dbd8305e13cb
Warn about non-string non-integer ARG to #'gensym, bytecomp.el.
lisp/ChangeLog addition:
2013-08-21 Aidan Kehoe <kehoea@parhasard.net>
* bytecomp.el:
* bytecomp.el (gensym):
* bytecomp.el (byte-compile-gensym): New.
Warn that gensym called in a for-effect context is unlikely to be
useful.
Warn about non-string non-integer ARGs, this is incorrect.
Am not changing the function to error with same, most code that
makes the mistake is has no problems, which is why it has survived
so long.
* window-xemacs.el (save-window-excursion/mapping):
* window.el (save-window-excursion):
Call #'gensym with a string, not a symbol.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Wed, 21 Aug 2013 19:02:59 +0100 |
parents | 0af042a0c116 |
children |
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 | |
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 | 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 | 22 |
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 | 25 |
2153 | 26 ;;; Synched up with: FSF 21.3. |
428 | 27 |
28 ;;; Commentary: | |
29 | |
30 ;; This file is dumped with XEmacs. | |
31 | |
32 ;; These are extensions to Emacs Lisp that provide a degree of | |
33 ;; Common Lisp compatibility, beyond what is already built-in | |
34 ;; in Emacs Lisp. | |
35 ;; | |
36 ;; This package was written by Dave Gillespie; it is a complete | |
37 ;; rewrite of Cesar Quiroz's original cl.el package of December 1986. | |
38 ;; | |
39 ;; This package works with Emacs 18, Emacs 19, and Lucid Emacs 19. | |
40 ;; | |
41 ;; Bug reports, comments, and suggestions are welcome! | |
42 | |
43 ;; This file contains the Common Lisp sequence and list functions | |
44 ;; which take keyword arguments. | |
45 | |
46 ;; See cl.el for Change Log. | |
47 | |
48 ;;; Code: | |
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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 176 |
177 Return the index of the matching item, or nil if not found. | |
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 | 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 | 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 | 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 | 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 | 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 | 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 | 211 "Sort the argument SEQUENCE stably according to PREDICATE. |
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 | 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 | 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 | 222 "Find the first item satisfying PREDICATE in LIST. |
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 | 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 | 230 "Find the first item not satisfying PREDICATE in LIST. |
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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 340 |
341 Any element of TREE which matches is changed to NEW (via a call to `setcar'). | |
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 | 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 | 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 | 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 | 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 | 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 | 357 |
2153 | 358 ;;; arch-tag: ec1cc072-9006-4225-b6ba-d6b07ed1710c |
428 | 359 ;;; cl-seq.el ends here |