Mercurial > hg > xemacs-beta
annotate lisp/cl-seq.el @ 5327:d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
src/ChangeLog addition:
2010-12-30 Aidan Kehoe <kehoea@parhasard.net>
Move the heavy lifting from cl-seq.el to C, finally making those
functions first-class XEmacs citizens, with circularity checking,
built-in support for tests other than #'eql, and as much
compatibility with current Common Lisp as Paul Dietz' tests require.
* fns.c (check_eq_nokey, check_eq_key, check_eql_nokey)
(check_eql_key, check_equal_nokey, check_equal_key)
(check_equalp_nokey, check_equalp_key, check_string_match_nokey)
(check_string_match_key, check_other_nokey, check_other_key)
(check_if_nokey, check_if_key, check_match_eq_key)
(check_match_eql_key, check_match_equal_key)
(check_match_equalp_key, check_match_other_key): New. These are
basically to provide function pointers to be used by Lisp
functions that take TEST, TEST-NOT and KEY arguments.
(get_check_match_function_1, get_check_test_function)
(get_check_match_function): These functions work out which of the
previous list of functions to use, given the keywords supplied by
the user.
(count_with_tail): New. This is the bones of #'count.
(list_count_from_end, string_count_from_end): Utility functions
for #'count.
(Fcount): New, moved from cl-seq.el.
(list_position_cons_before): New. The implementation of #'member*,
and important in implementing various other functions.
(FmemberX, Fadjoin, FassocX, FrassocX, Fposition, Ffind)
(FdeleteX, FremoveX, Fdelete_duplicates, Fremove_duplicates)
(Fnsubstitute, Fsubstitute, Fsublis, Fnsublis, Fsubst, Fnsubst)
(Ftree_equal, Fmismatch, Fsearch, Fintersection, Fnintersection)
(Fsubsetp, Fset_difference, Fnset_difference, Fnunion, Funion)
(Fset_exclusive_or, Fnset_exclusive_or): New, moved here from
cl-seq.el.
(position): New. The implementation of #'find and #'position.
(list_delete_duplicates_from_end, subst, sublis, nsublis)
(tree_equal, mismatch_from_end, mismatch_list_list)
(mismatch_list_string, mismatch_list_array)
(mismatch_string_array, mismatch_string_string)
(mismatch_array_array, get_mismatch_func): Helper C functions for
the Lisp-visible functions.
(venn, nvenn): New. The implementation of the main Lisp functions that
treat lists as sets.
lisp/ChangeLog addition:
2010-12-30 Aidan Kehoe <kehoea@parhasard.net>
* cl-seq.el:
Move the heavy lifting from this file to C. Dump the
cl-parsing-keywords macro, but don't use defun* for the functions
we define that do take keywords, dynamic scope lossage makes that
not practical.
* subr.el (sort, fillarray): Move these aliases here.
(map-plist): #'nsublis is now built-in, but at this point #'eql
isn't necessarily available as a test; use #'eq.
* obsolete.el (cl-delete-duplicates): Make this available for old
compiler macros and old code.
(memql): Document that this is equivalent to #'member*, and worse.
* cl.el (adjoin, subst): Removed. These are in C.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Thu, 30 Dec 2010 01:59:52 +0000 |
parents | 69f687b3ba9d |
children | b4ef3128160c 89331fa1c819 |
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 ;; XEmacs change: these two are in subr.el in GNU Emacs. |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
60 (defun remove (cl-item cl-seq) |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
61 "Remove all occurrences of ITEM in SEQUENCE, testing with `equal'. |
442 | 62 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
63 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
|
64 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
|
65 Also see: `remove*', `delete', `delete*' |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
66 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
67 arguments: (ITEM SEQUENCE)" |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
68 (remove* cl-item cl-seq :test #'equal)) |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
69 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
70 (defun remq (cl-item cl-seq) |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
71 "Remove all occurrences of ITEM in SEQUENCE, comparing with `eq'. |
442 | 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 to avoid |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
74 corrupting the original LIST. See also the more general `remove*'. |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
75 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
76 arguments: (ITEM SEQUENCE)" |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
77 (remove* cl-item cl-seq :test #'eq)) |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
78 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
79 (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
|
80 "Remove all items satisfying PREDICATE in SEQUENCE. |
428 | 81 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
82 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
|
83 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
|
84 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
|
85 SEQUENCE itself is returned, unmodified. |
428 | 86 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
87 See `remove*' for the meaning of the keywords. |
428 | 88 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
89 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
|
90 (apply 'remove* 'remove* cl-seq :if cl-predicate cl-keys)) |
428 | 91 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
92 (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
|
93 "Remove all items not satisfying PREDICATE in SEQUENCE. |
428 | 94 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
95 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
|
96 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
|
97 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
|
98 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
99 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
|
100 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
101 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
|
102 (apply 'remove* 'remove* cl-seq :if-not cl-predicate cl-keys)) |
428 | 103 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
104 (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
|
105 "Remove all items satisfying PREDICATE in SEQUENCE. |
428 | 106 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
107 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
|
108 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
|
109 copy is always returned. |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
110 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
111 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
|
112 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
113 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
|
114 (apply 'delete* 'delete* 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 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
|
117 "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
|
118 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
119 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
|
120 possible. |
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: (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
|
125 (apply 'delete* 'delete* cl-seq :if-not cl-predicate cl-keys)) |
428 | 126 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
127 (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
|
128 "Substitute NEW for all items satisfying PREDICATE in SEQUENCE. |
428 | 129 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
130 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
|
131 to avoid corrupting the original SEQUENCE. |
428 | 132 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
133 See `remove*' for the meaning of the keywords. |
428 | 134 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
135 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
|
136 (apply 'substitute cl-new 'substitute cl-seq :if cl-predicate cl-keys)) |
428 | 137 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
138 (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
|
139 "Substitute NEW for all items not satisfying PREDICATE in SEQUENCE. |
428 | 140 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
141 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
|
142 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
|
143 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
144 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
|
145 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
146 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
|
147 (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
|
148 cl-keys)) |
428 | 149 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
150 (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
|
151 "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
|
152 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
153 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
|
154 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
|
155 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
156 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
|
157 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
158 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
|
159 (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
|
160 cl-keys)) |
428 | 161 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
162 (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
|
163 "Substitute NEW for all items not satisfying PREDICATE in SEQUENCE. |
428 | 164 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
165 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
|
166 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
|
167 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
168 See `remove*' for the meaning of the keywords. |
428 | 169 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
170 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
|
171 (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
|
172 cl-keys)) |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
173 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
174 (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
|
175 "Find the first item satisfying PREDICATE in SEQUENCE. |
428 | 176 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
177 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
|
178 function by Common Lisp) if not found. |
428 | 179 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
180 See `remove*' for the meaning of the other keywords. |
428 | 181 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
182 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
|
183 (apply 'find 'find cl-seq :if cl-predicate cl-keys)) |
428 | 184 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
185 (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
|
186 "Find the first item not satisfying PREDICATE in SEQUENCE. |
428 | 187 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
188 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
|
189 function by Common Lisp) if not found. |
428 | 190 |
5327
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. |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
192 |
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 DEFAULT)" |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
194 (apply 'find 'find cl-seq :if-not cl-predicate cl-keys)) |
428 | 195 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
196 (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
|
197 "Find the first item satisfying PREDICATE in SEQUENCE. |
428 | 198 |
199 Return the index of the matching item, or nil if not found. | |
200 | |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
201 See `remove*' for the meaning of the keywords. |
428 | 202 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
203 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
|
204 (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
|
205 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
206 (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
|
207 "Find the first item not satisfying PREDICATE in SEQUENCE. |
428 | 208 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
209 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
|
210 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
211 See `remove*' for the meaning of the keywords. |
428 | 212 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
213 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
|
214 (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
|
215 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
216 (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
|
217 "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
|
218 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
219 See `remove*' for the meaning of the keywords. |
428 | 220 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
221 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
|
222 (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
|
223 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
224 (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
|
225 "Count the number of items not satisfying PREDICATE in SEQUENCE. |
428 | 226 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
227 See `remove*' for the meaning of the keywords. |
428 | 228 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
229 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
|
230 (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
|
231 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
232 (defun stable-sort (cl-seq cl-predicate &rest cl-keys) |
428 | 233 "Sort the argument SEQUENCE stably according to PREDICATE. |
234 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
|
235 Keywords supported: :key |
545ec923b4eb
add documentation on keywords to cl*.el
Ben Wing <ben@xemacs.org>
parents:
4885
diff
changeset
|
236 :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
|
237 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
|
238 `member*' for more information. |
428 | 239 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
240 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
|
241 (apply 'sort* cl-seq cl-predicate cl-keys)) |
428 | 242 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
243 (defun member-if (cl-predicate cl-list &rest cl-keys) |
428 | 244 "Find the first item satisfying PREDICATE in LIST. |
245 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
|
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 LIST &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 '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
|
250 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
251 (defun member-if-not (cl-predicate cl-list &rest cl-keys) |
428 | 252 "Find the first item not satisfying PREDICATE in LIST. |
253 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
|
254 See `member*' for the meaning of :key. |
428 | 255 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
256 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
|
257 (apply 'member* 'member* cl-list :if-not cl-predicate cl-keys)) |
428 | 258 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
259 (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
|
260 "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
|
261 See `member*' for the meaning of :key. |
428 | 262 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
263 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
|
264 (apply 'assoc* 'assoc* cl-alist :if cl-predicate cl-keys)) |
428 | 265 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
266 (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
|
267 "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
|
268 See `member*' for the meaning of :key. |
428 | 269 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
270 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
|
271 (apply 'assoc* 'assoc* cl-alist :if-not cl-predicate cl-keys)) |
428 | 272 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
273 (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
|
274 "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
|
275 See `member*' for the meaning of :key. |
428 | 276 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
277 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
|
278 (apply 'rassoc* 'rassoc* cl-alist :if cl-predicate cl-keys)) |
428 | 279 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
280 (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
|
281 "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
|
282 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
|
283 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
284 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
|
285 (apply 'rassoc* 'rassoc* cl-alist :if-not cl-predicate cl-keys)) |
428 | 286 |
5067
7d7ae8db0341
add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents:
5066
diff
changeset
|
287 ;; 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
|
288 (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
|
289 "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
|
290 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
|
291 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
|
292 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
|
293 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
|
294 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
|
295 |
5067
7d7ae8db0341
add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents:
5066
diff
changeset
|
296 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
|
297 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
|
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 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
|
300 |
7d7ae8db0341
add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents:
5066
diff
changeset
|
301 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
|
302 extension. |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
303 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
304 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
|
305 ;; 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
|
306 ;; 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
|
307 ;; 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
|
308 ;; `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
|
309 ;; 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
|
310 ;; semantics of `union'. |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
311 (apply 'union cl-list1 cl-list2 :stable t cl-keys)) |
428 | 312 |
5067
7d7ae8db0341
add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents:
5066
diff
changeset
|
313 ;; 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
|
314 (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
|
315 "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
|
316 |
5067
7d7ae8db0341
add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents:
5066
diff
changeset
|
317 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
|
318 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
|
319 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
|
320 |
5067
7d7ae8db0341
add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents:
5066
diff
changeset
|
321 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
|
322 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
|
323 |
5067
7d7ae8db0341
add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents:
5066
diff
changeset
|
324 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
|
325 |
7d7ae8db0341
add functions `stable-union' and `stable-intersection' to do stable set operations
Ben Wing <ben@xemacs.org>
parents:
5066
diff
changeset
|
326 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
|
327 extension. |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
328 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
329 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
|
330 ;; 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
|
331 ;; 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
|
332 ;; 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
|
333 ;; `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
|
334 ;; 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
|
335 ;; 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
|
336 (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
|
337 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
338 (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
|
339 "Substitute NEW for elements matching PREDICATE in TREE (non-destructively). |
428 | 340 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
341 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
|
342 element matches PREDICATE, return tree. |
428 | 343 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
344 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
|
345 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
346 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
|
347 (apply 'subst cl-new 'subst cl-tree :if cl-predicate cl-keys)) |
428 | 348 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
349 (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
|
350 "Substitute NEW for elements not matching PREDICATE in TREE. |
428 | 351 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
352 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
|
353 element matches PREDICATE, return tree. |
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 'subst cl-new 'subst cl-tree :if-not cl-predicate cl-keys)) |
428 | 359 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
360 (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
|
361 "Substitute NEW for elements matching PREDICATE in TREE (destructively). |
428 | 362 |
363 Any element of TREE which matches is changed to NEW (via a call to `setcar'). | |
364 | |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
365 See `member*' for the meaning of :key. |
428 | 366 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
367 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
|
368 (apply 'nsubst cl-new 'nsubst cl-tree :if cl-predicate cl-keys)) |
428 | 369 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
370 (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
|
371 "Substitute NEW for elements not matching PREDICATE in TREE (destructively). |
428 | 372 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
373 Any element of TREE which matches is changed to NEW (via a call to `setcar'). |
428 | 374 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
375 See `member*' for the meaning of :key. |
428 | 376 |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5261
diff
changeset
|
377 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
|
378 (apply 'nsubst cl-new 'nsubst cl-tree :if-not cl-predicate cl-keys)) |
428 | 379 |
2153 | 380 ;;; arch-tag: ec1cc072-9006-4225-b6ba-d6b07ed1710c |
428 | 381 ;;; cl-seq.el ends here |