| 1 |
This is ../info/cl, produced by makeinfo version 4.2 from cl.texi. |
|---|
| 2 |
|
|---|
| 3 |
INFO-DIR-SECTION Emacs |
|---|
| 4 |
START-INFO-DIR-ENTRY |
|---|
| 5 |
* CL: (cl). Partial Common Lisp support for Emacs Lisp. |
|---|
| 6 |
END-INFO-DIR-ENTRY |
|---|
| 7 |
|
|---|
| 8 |
This file documents the GNU Emacs Common Lisp emulation package. |
|---|
| 9 |
|
|---|
| 10 |
Copyright (C) 1993 Free Software Foundation, Inc. |
|---|
| 11 |
|
|---|
| 12 |
Permission is granted to copy, distribute and/or modify this document |
|---|
| 13 |
under the terms of the GNU Free Documentation License, Version 1.1 or |
|---|
| 14 |
any later version published by the Free Software Foundation; with no |
|---|
| 15 |
Invariant Sections, with the Front-Cover texts being "A GNU Manual", |
|---|
| 16 |
and with the Back-Cover Texts as in (a) below. A copy of the license |
|---|
| 17 |
is included in the section entitled "GNU Free Documentation License" in |
|---|
| 18 |
the Emacs manual. |
|---|
| 19 |
|
|---|
| 20 |
(a) The FSF's Back-Cover Text is: "You have freedom to copy and |
|---|
| 21 |
modify this GNU Manual, like GNU software. Copies published by the Free |
|---|
| 22 |
Software Foundation raise funds for GNU development." |
|---|
| 23 |
|
|---|
| 24 |
This document is part of a collection distributed under the GNU Free |
|---|
| 25 |
Documentation License. If you want to distribute this document |
|---|
| 26 |
separately from the collection, you can do so by adding a copy of the |
|---|
| 27 |
license to the document, as described in section 6 of the license. |
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
File: cl, Node: Implementation Parameters, Prev: Random Numbers, Up: Numbers |
|---|
| 31 |
|
|---|
| 32 |
Implementation Parameters |
|---|
| 33 |
========================= |
|---|
| 34 |
|
|---|
| 35 |
This package defines several useful constants having to with numbers. |
|---|
| 36 |
|
|---|
| 37 |
- Variable: most-positive-fixnum |
|---|
| 38 |
This constant equals the largest value a Lisp integer can hold. |
|---|
| 39 |
It is typically `2^23-1' or `2^25-1'. |
|---|
| 40 |
|
|---|
| 41 |
- Variable: most-negative-fixnum |
|---|
| 42 |
This constant equals the smallest (most negative) value a Lisp |
|---|
| 43 |
integer can hold. |
|---|
| 44 |
|
|---|
| 45 |
The following parameters have to do with floating-point numbers. |
|---|
| 46 |
This package determines their values by exercising the computer's |
|---|
| 47 |
floating-point arithmetic in various ways. Because this operation |
|---|
| 48 |
might be slow, the code for initializing them is kept in a separate |
|---|
| 49 |
function that must be called before the parameters can be used. |
|---|
| 50 |
|
|---|
| 51 |
- Function: cl-float-limits |
|---|
| 52 |
This function makes sure that the Common Lisp floating-point |
|---|
| 53 |
parameters like `most-positive-float' have been initialized. |
|---|
| 54 |
Until it is called, these parameters will be `nil'. If this |
|---|
| 55 |
version of Emacs does not support floats, the parameters will |
|---|
| 56 |
remain `nil'. If the parameters have already been initialized, |
|---|
| 57 |
the function returns immediately. |
|---|
| 58 |
|
|---|
| 59 |
The algorithm makes assumptions that will be valid for most modern |
|---|
| 60 |
machines, but will fail if the machine's arithmetic is extremely |
|---|
| 61 |
unusual, e.g., decimal. |
|---|
| 62 |
|
|---|
| 63 |
Since true Common Lisp supports up to four different floating-point |
|---|
| 64 |
precisions, it has families of constants like |
|---|
| 65 |
`most-positive-single-float', `most-positive-double-float', |
|---|
| 66 |
`most-positive-long-float', and so on. Emacs has only one |
|---|
| 67 |
floating-point precision, so this package omits the precision word from |
|---|
| 68 |
the constants' names. |
|---|
| 69 |
|
|---|
| 70 |
- Variable: most-positive-float |
|---|
| 71 |
This constant equals the largest value a Lisp float can hold. For |
|---|
| 72 |
those systems whose arithmetic supports infinities, this is the |
|---|
| 73 |
largest _finite_ value. For IEEE machines, the value is |
|---|
| 74 |
approximately `1.79e+308'. |
|---|
| 75 |
|
|---|
| 76 |
- Variable: most-negative-float |
|---|
| 77 |
This constant equals the most-negative value a Lisp float can hold. |
|---|
| 78 |
(It is assumed to be equal to `(- most-positive-float)'.) |
|---|
| 79 |
|
|---|
| 80 |
- Variable: least-positive-float |
|---|
| 81 |
This constant equals the smallest Lisp float value greater than |
|---|
| 82 |
zero. For IEEE machines, it is about `4.94e-324' if denormals are |
|---|
| 83 |
supported or `2.22e-308' if not. |
|---|
| 84 |
|
|---|
| 85 |
- Variable: least-positive-normalized-float |
|---|
| 86 |
This constant equals the smallest _normalized_ Lisp float greater |
|---|
| 87 |
than zero, i.e., the smallest value for which IEEE denormalization |
|---|
| 88 |
will not result in a loss of precision. For IEEE machines, this |
|---|
| 89 |
value is about `2.22e-308'. For machines that do not support the |
|---|
| 90 |
concept of denormalization and gradual underflow, this constant |
|---|
| 91 |
will always equal `least-positive-float'. |
|---|
| 92 |
|
|---|
| 93 |
- Variable: least-negative-float |
|---|
| 94 |
This constant is the negative counterpart of |
|---|
| 95 |
`least-positive-float'. |
|---|
| 96 |
|
|---|
| 97 |
- Variable: least-negative-normalized-float |
|---|
| 98 |
This constant is the negative counterpart of |
|---|
| 99 |
`least-positive-normalized-float'. |
|---|
| 100 |
|
|---|
| 101 |
- Variable: float-epsilon |
|---|
| 102 |
This constant is the smallest positive Lisp float that can be added |
|---|
| 103 |
to 1.0 to produce a distinct value. Adding a smaller number to 1.0 |
|---|
| 104 |
will yield 1.0 again due to roundoff. For IEEE machines, epsilon |
|---|
| 105 |
is about `2.22e-16'. |
|---|
| 106 |
|
|---|
| 107 |
- Variable: float-negative-epsilon |
|---|
| 108 |
This is the smallest positive value that can be subtracted from |
|---|
| 109 |
1.0 to produce a distinct value. For IEEE machines, it is about |
|---|
| 110 |
`1.11e-16'. |
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 |
File: cl, Node: Sequences, Next: Lists, Prev: Numbers, Up: Top |
|---|
| 114 |
|
|---|
| 115 |
Sequences |
|---|
| 116 |
********* |
|---|
| 117 |
|
|---|
| 118 |
Common Lisp defines a number of functions that operate on "sequences", |
|---|
| 119 |
which are either lists, strings, or vectors. Emacs Lisp includes a few |
|---|
| 120 |
of these, notably `elt' and `length'; this package defines most of the |
|---|
| 121 |
rest. |
|---|
| 122 |
|
|---|
| 123 |
* Menu: |
|---|
| 124 |
|
|---|
| 125 |
* Sequence Basics:: Arguments shared by all sequence functions |
|---|
| 126 |
* Mapping over Sequences:: `mapcar*', `mapcan', `map', `every', etc. |
|---|
| 127 |
* Sequence Functions:: `subseq', `remove*', `substitute', etc. |
|---|
| 128 |
* Searching Sequences:: `find', `position', `count', `search', etc. |
|---|
| 129 |
* Sorting Sequences:: `sort*', `stable-sort', `merge' |
|---|
| 130 |
|
|---|
| 131 |
|
|---|
| 132 |
File: cl, Node: Sequence Basics, Next: Mapping over Sequences, Prev: Sequences, Up: Sequences |
|---|
| 133 |
|
|---|
| 134 |
Sequence Basics |
|---|
| 135 |
=============== |
|---|
| 136 |
|
|---|
| 137 |
Many of the sequence functions take keyword arguments; *note Argument |
|---|
| 138 |
Lists::. All keyword arguments are optional and, if specified, may |
|---|
| 139 |
appear in any order. |
|---|
| 140 |
|
|---|
| 141 |
The `:key' argument should be passed either `nil', or a function of |
|---|
| 142 |
one argument. This key function is used as a filter through which the |
|---|
| 143 |
elements of the sequence are seen; for example, `(find x y :key 'car)' |
|---|
| 144 |
is similar to `(assoc* x y)': It searches for an element of the list |
|---|
| 145 |
whose `car' equals `x', rather than for an element which equals `x' |
|---|
| 146 |
itself. If `:key' is omitted or `nil', the filter is effectively the |
|---|
| 147 |
identity function. |
|---|
| 148 |
|
|---|
| 149 |
The `:test' and `:test-not' arguments should be either `nil', or |
|---|
| 150 |
functions of two arguments. The test function is used to compare two |
|---|
| 151 |
sequence elements, or to compare a search value with sequence elements. |
|---|
| 152 |
(The two values are passed to the test function in the same order as |
|---|
| 153 |
the original sequence function arguments from which they are derived, |
|---|
| 154 |
or, if they both come from the same sequence, in the same order as they |
|---|
| 155 |
appear in that sequence.) The `:test' argument specifies a function |
|---|
| 156 |
which must return true (non-`nil') to indicate a match; instead, you |
|---|
| 157 |
may use `:test-not' to give a function which returns _false_ to |
|---|
| 158 |
indicate a match. The default test function is `:test 'eql'. |
|---|
| 159 |
|
|---|
| 160 |
Many functions which take ITEM and `:test' or `:test-not' arguments |
|---|
| 161 |
also come in `-if' and `-if-not' varieties, where a PREDICATE function |
|---|
| 162 |
is passed instead of ITEM, and sequence elements match if the predicate |
|---|
| 163 |
returns true on them (or false in the case of `-if-not'). For example: |
|---|
| 164 |
|
|---|
| 165 |
(remove* 0 seq :test '=) == (remove-if 'zerop seq) |
|---|
| 166 |
|
|---|
| 167 |
to remove all zeros from sequence `seq'. |
|---|
| 168 |
|
|---|
| 169 |
Some operations can work on a subsequence of the argument sequence; |
|---|
| 170 |
these function take `:start' and `:end' arguments which default to zero |
|---|
| 171 |
and the length of the sequence, respectively. Only elements between |
|---|
| 172 |
START (inclusive) and END (exclusive) are affected by the operation. |
|---|
| 173 |
The END argument may be passed `nil' to signify the length of the |
|---|
| 174 |
sequence; otherwise, both START and END must be integers, with `0 <= |
|---|
| 175 |
START <= END <= (length SEQ)'. If the function takes two sequence |
|---|
| 176 |
arguments, the limits are defined by keywords `:start1' and `:end1' for |
|---|
| 177 |
the first, and `:start2' and `:end2' for the second. |
|---|
| 178 |
|
|---|
| 179 |
A few functions accept a `:from-end' argument, which, if non-`nil', |
|---|
| 180 |
causes the operation to go from right-to-left through the sequence |
|---|
| 181 |
instead of left-to-right, and a `:count' argument, which specifies an |
|---|
| 182 |
integer maximum number of elements to be removed or otherwise processed. |
|---|
| 183 |
|
|---|
| 184 |
The sequence functions make no guarantees about the order in which |
|---|
| 185 |
the `:test', `:test-not', and `:key' functions are called on various |
|---|
| 186 |
elements. Therefore, it is a bad idea to depend on side effects of |
|---|
| 187 |
these functions. For example, `:from-end' may cause the sequence to be |
|---|
| 188 |
scanned actually in reverse, or it may be scanned forwards but |
|---|
| 189 |
computing a result "as if" it were scanned backwards. (Some functions, |
|---|
| 190 |
like `mapcar*' and `every', _do_ specify exactly the order in which the |
|---|
| 191 |
function is called so side effects are perfectly acceptable in those |
|---|
| 192 |
cases.) |
|---|
| 193 |
|
|---|
| 194 |
Strings may contain "text properties" as well as character data. |
|---|
| 195 |
Except as noted, it is undefined whether or not text properties are |
|---|
| 196 |
preserved by sequence functions. For example, `(remove* ?A STR)' may |
|---|
| 197 |
or may not preserve the properties of the characters copied from STR |
|---|
| 198 |
into the result. |
|---|
| 199 |
|
|---|
| 200 |
|
|---|
| 201 |
File: cl, Node: Mapping over Sequences, Next: Sequence Functions, Prev: Sequence Basics, Up: Sequences |
|---|
| 202 |
|
|---|
| 203 |
Mapping over Sequences |
|---|
| 204 |
====================== |
|---|
| 205 |
|
|---|
| 206 |
These functions "map" the function you specify over the elements of |
|---|
| 207 |
lists or arrays. They are all variations on the theme of the built-in |
|---|
| 208 |
function `mapcar'. |
|---|
| 209 |
|
|---|
| 210 |
- Function: mapcar* function seq &rest more-seqs |
|---|
| 211 |
This function calls FUNCTION on successive parallel sets of |
|---|
| 212 |
elements from its argument sequences. Given a single SEQ argument |
|---|
| 213 |
it is equivalent to `mapcar'; given N sequences, it calls the |
|---|
| 214 |
function with the first elements of each of the sequences as the N |
|---|
| 215 |
arguments to yield the first element of the result list, then with |
|---|
| 216 |
the second elements, and so on. The mapping stops as soon as the |
|---|
| 217 |
shortest sequence runs out. The argument sequences may be any |
|---|
| 218 |
mixture of lists, strings, and vectors; the return sequence is |
|---|
| 219 |
always a list. |
|---|
| 220 |
|
|---|
| 221 |
Common Lisp's `mapcar' accepts multiple arguments but works only |
|---|
| 222 |
on lists; Emacs Lisp's `mapcar' accepts a single sequence |
|---|
| 223 |
argument. This package's `mapcar*' works as a compatible superset |
|---|
| 224 |
of both. |
|---|
| 225 |
|
|---|
| 226 |
- Function: map result-type function seq &rest more-seqs |
|---|
| 227 |
This function maps FUNCTION over the argument sequences, just like |
|---|
| 228 |
`mapcar*', but it returns a sequence of type RESULT-TYPE rather |
|---|
| 229 |
than a list. RESULT-TYPE must be one of the following symbols: |
|---|
| 230 |
`vector', `string', `list' (in which case the effect is the same |
|---|
| 231 |
as for `mapcar*'), or `nil' (in which case the results are thrown |
|---|
| 232 |
away and `map' returns `nil'). |
|---|
| 233 |
|
|---|
| 234 |
- Function: maplist function list &rest more-lists |
|---|
| 235 |
This function calls FUNCTION on each of its argument lists, then |
|---|
| 236 |
on the `cdr's of those lists, and so on, until the shortest list |
|---|
| 237 |
runs out. The results are returned in the form of a list. Thus, |
|---|
| 238 |
`maplist' is like `mapcar*' except that it passes in the list |
|---|
| 239 |
pointers themselves rather than the `car's of the advancing |
|---|
| 240 |
pointers. |
|---|
| 241 |
|
|---|
| 242 |
- Function: mapc function seq &rest more-seqs |
|---|
| 243 |
This function is like `mapcar*', except that the values returned |
|---|
| 244 |
by FUNCTION are ignored and thrown away rather than being |
|---|
| 245 |
collected into a list. The return value of `mapc' is SEQ, the |
|---|
| 246 |
first sequence. This function is more general than the Emacs |
|---|
| 247 |
primitive `mapc'. |
|---|
| 248 |
|
|---|
| 249 |
- Function: mapl function list &rest more-lists |
|---|
| 250 |
This function is like `maplist', except that it throws away the |
|---|
| 251 |
values returned by FUNCTION. |
|---|
| 252 |
|
|---|
| 253 |
- Function: mapcan function seq &rest more-seqs |
|---|
| 254 |
This function is like `mapcar*', except that it concatenates the |
|---|
| 255 |
return values (which must be lists) using `nconc', rather than |
|---|
| 256 |
simply collecting them into a list. |
|---|
| 257 |
|
|---|
| 258 |
- Function: mapcon function list &rest more-lists |
|---|
| 259 |
This function is like `maplist', except that it concatenates the |
|---|
| 260 |
return values using `nconc'. |
|---|
| 261 |
|
|---|
| 262 |
- Function: some predicate seq &rest more-seqs |
|---|
| 263 |
This function calls PREDICATE on each element of SEQ in turn; if |
|---|
| 264 |
PREDICATE returns a non-`nil' value, `some' returns that value, |
|---|
| 265 |
otherwise it returns `nil'. Given several sequence arguments, it |
|---|
| 266 |
steps through the sequences in parallel until the shortest one |
|---|
| 267 |
runs out, just as in `mapcar*'. You can rely on the left-to-right |
|---|
| 268 |
order in which the elements are visited, and on the fact that |
|---|
| 269 |
mapping stops immediately as soon as PREDICATE returns non-`nil'. |
|---|
| 270 |
|
|---|
| 271 |
- Function: every predicate seq &rest more-seqs |
|---|
| 272 |
This function calls PREDICATE on each element of the sequence(s) |
|---|
| 273 |
in turn; it returns `nil' as soon as PREDICATE returns `nil' for |
|---|
| 274 |
any element, or `t' if the predicate was true for all elements. |
|---|
| 275 |
|
|---|
| 276 |
- Function: notany predicate seq &rest more-seqs |
|---|
| 277 |
This function calls PREDICATE on each element of the sequence(s) |
|---|
| 278 |
in turn; it returns `nil' as soon as PREDICATE returns a non-`nil' |
|---|
| 279 |
value for any element, or `t' if the predicate was `nil' for all |
|---|
| 280 |
elements. |
|---|
| 281 |
|
|---|
| 282 |
- Function: notevery predicate seq &rest more-seqs |
|---|
| 283 |
This function calls PREDICATE on each element of the sequence(s) |
|---|
| 284 |
in turn; it returns a non-`nil' value as soon as PREDICATE returns |
|---|
| 285 |
`nil' for any element, or `t' if the predicate was true for all |
|---|
| 286 |
elements. |
|---|
| 287 |
|
|---|
| 288 |
- Function: reduce function seq &key :from-end :start :end |
|---|
| 289 |
:initial-value :key |
|---|
| 290 |
This function combines the elements of SEQ using an associative |
|---|
| 291 |
binary operation. Suppose FUNCTION is `*' and SEQ is the list `(2 |
|---|
| 292 |
3 4 5)'. The first two elements of the list are combined with `(* |
|---|
| 293 |
2 3) = 6'; this is combined with the next element, `(* 6 4) = 24', |
|---|
| 294 |
and that is combined with the final element: `(* 24 5) = 120'. |
|---|
| 295 |
Note that the `*' function happens to be self-reducing, so that |
|---|
| 296 |
`(* 2 3 4 5)' has the same effect as an explicit call to `reduce'. |
|---|
| 297 |
|
|---|
| 298 |
If `:from-end' is true, the reduction is right-associative instead |
|---|
| 299 |
of left-associative: |
|---|
| 300 |
|
|---|
| 301 |
(reduce '- '(1 2 3 4)) |
|---|
| 302 |
== (- (- (- 1 2) 3) 4) => -8 |
|---|
| 303 |
(reduce '- '(1 2 3 4) :from-end t) |
|---|
| 304 |
== (- 1 (- 2 (- 3 4))) => -2 |
|---|
| 305 |
|
|---|
| 306 |
If `:key' is specified, it is a function of one argument which is |
|---|
| 307 |
called on each of the sequence elements in turn. |
|---|
| 308 |
|
|---|
| 309 |
If `:initial-value' is specified, it is effectively added to the |
|---|
| 310 |
front (or rear in the case of `:from-end') of the sequence. The |
|---|
| 311 |
`:key' function is _not_ applied to the initial value. |
|---|
| 312 |
|
|---|
| 313 |
If the sequence, including the initial value, has exactly one |
|---|
| 314 |
element then that element is returned without ever calling |
|---|
| 315 |
FUNCTION. If the sequence is empty (and there is no initial |
|---|
| 316 |
value), then FUNCTION is called with no arguments to obtain the |
|---|
| 317 |
return value. |
|---|
| 318 |
|
|---|
| 319 |
All of these mapping operations can be expressed conveniently in |
|---|
| 320 |
terms of the `loop' macro. In compiled code, `loop' will be faster |
|---|
| 321 |
since it generates the loop as in-line code with no function calls. |
|---|
| 322 |
|
|---|
| 323 |
|
|---|
| 324 |
File: cl, Node: Sequence Functions, Next: Searching Sequences, Prev: Mapping over Sequences, Up: Sequences |
|---|
| 325 |
|
|---|
| 326 |
Sequence Functions |
|---|
| 327 |
================== |
|---|
| 328 |
|
|---|
| 329 |
This section describes a number of Common Lisp functions for operating |
|---|
| 330 |
on sequences. |
|---|
| 331 |
|
|---|
| 332 |
- Function: subseq sequence start &optional end |
|---|
| 333 |
This function returns a given subsequence of the argument |
|---|
| 334 |
SEQUENCE, which may be a list, string, or vector. The indices |
|---|
| 335 |
START and END must be in range, and START must be no greater than |
|---|
| 336 |
END. If END is omitted, it defaults to the length of the |
|---|
| 337 |
sequence. The return value is always a copy; it does not share |
|---|
| 338 |
structure with SEQUENCE. |
|---|
| 339 |
|
|---|
| 340 |
As an extension to Common Lisp, START and/or END may be negative, |
|---|
| 341 |
in which case they represent a distance back from the end of the |
|---|
| 342 |
sequence. This is for compatibility with Emacs' `substring' |
|---|
| 343 |
function. Note that `subseq' is the _only_ sequence function that |
|---|
| 344 |
allows negative START and END. |
|---|
| 345 |
|
|---|
| 346 |
You can use `setf' on a `subseq' form to replace a specified range |
|---|
| 347 |
of elements with elements from another sequence. The replacement |
|---|
| 348 |
is done as if by `replace', described below. |
|---|
| 349 |
|
|---|
| 350 |
- Function: concatenate result-type &rest seqs |
|---|
| 351 |
This function concatenates the argument sequences together to form |
|---|
| 352 |
a result sequence of type RESULT-TYPE, one of the symbols |
|---|
| 353 |
`vector', `string', or `list'. The arguments are always copied, |
|---|
| 354 |
even in cases such as `(concatenate 'list '(1 2 3))' where the |
|---|
| 355 |
result is identical to an argument. |
|---|
| 356 |
|
|---|
| 357 |
- Function: fill seq item &key :start :end |
|---|
| 358 |
This function fills the elements of the sequence (or the specified |
|---|
| 359 |
part of the sequence) with the value ITEM. |
|---|
| 360 |
|
|---|
| 361 |
- Function: replace seq1 seq2 &key :start1 :end1 :start2 :end2 |
|---|
| 362 |
This function copies part of SEQ2 into part of SEQ1. The sequence |
|---|
| 363 |
SEQ1 is not stretched or resized; the amount of data copied is |
|---|
| 364 |
simply the shorter of the source and destination (sub)sequences. |
|---|
| 365 |
The function returns SEQ1. |
|---|
| 366 |
|
|---|
| 367 |
If SEQ1 and SEQ2 are `eq', then the replacement will work |
|---|
| 368 |
correctly even if the regions indicated by the start and end |
|---|
| 369 |
arguments overlap. However, if SEQ1 and SEQ2 are lists which |
|---|
| 370 |
share storage but are not `eq', and the start and end arguments |
|---|
| 371 |
specify overlapping regions, the effect is undefined. |
|---|
| 372 |
|
|---|
| 373 |
- Function: remove* item seq &key :test :test-not :key :count :start |
|---|
| 374 |
:end :from-end |
|---|
| 375 |
This returns a copy of SEQ with all elements matching ITEM |
|---|
| 376 |
removed. The result may share storage with or be `eq' to SEQ in |
|---|
| 377 |
some circumstances, but the original SEQ will not be modified. |
|---|
| 378 |
The `:test', `:test-not', and `:key' arguments define the matching |
|---|
| 379 |
test that is used; by default, elements `eql' to ITEM are removed. |
|---|
| 380 |
The `:count' argument specifies the maximum number of matching |
|---|
| 381 |
elements that can be removed (only the leftmost COUNT matches are |
|---|
| 382 |
removed). The `:start' and `:end' arguments specify a region in |
|---|
| 383 |
SEQ in which elements will be removed; elements outside that |
|---|
| 384 |
region are not matched or removed. The `:from-end' argument, if |
|---|
| 385 |
true, says that elements should be deleted from the end of the |
|---|
| 386 |
sequence rather than the beginning (this matters only if COUNT was |
|---|
| 387 |
also specified). |
|---|
| 388 |
|
|---|
| 389 |
- Function: delete* item seq &key :test :test-not :key :count :start |
|---|
| 390 |
:end :from-end |
|---|
| 391 |
This deletes all elements of SEQ which match ITEM. It is a |
|---|
| 392 |
destructive operation. Since Emacs Lisp does not support |
|---|
| 393 |
stretchable strings or vectors, this is the same as `remove*' for |
|---|
| 394 |
those sequence types. On lists, `remove*' will copy the list if |
|---|
| 395 |
necessary to preserve the original list, whereas `delete*' will |
|---|
| 396 |
splice out parts of the argument list. Compare `append' and |
|---|
| 397 |
`nconc', which are analogous non-destructive and destructive list |
|---|
| 398 |
operations in Emacs Lisp. |
|---|
| 399 |
|
|---|
| 400 |
The predicate-oriented functions `remove-if', `remove-if-not', |
|---|
| 401 |
`delete-if', and `delete-if-not' are defined similarly. |
|---|
| 402 |
|
|---|
| 403 |
- Function: remove-duplicates seq &key :test :test-not :key :start |
|---|
| 404 |
:end :from-end |
|---|
| 405 |
This function returns a copy of SEQ with duplicate elements |
|---|
| 406 |
removed. Specifically, if two elements from the sequence match |
|---|
| 407 |
according to the `:test', `:test-not', and `:key' arguments, only |
|---|
| 408 |
the rightmost one is retained. If `:from-end' is true, the |
|---|
| 409 |
leftmost one is retained instead. If `:start' or `:end' is |
|---|
| 410 |
specified, only elements within that subsequence are examined or |
|---|
| 411 |
removed. |
|---|
| 412 |
|
|---|
| 413 |
- Function: delete-duplicates seq &key :test :test-not :key :start |
|---|
| 414 |
:end :from-end |
|---|
| 415 |
This function deletes duplicate elements from SEQ. It is a |
|---|
| 416 |
destructive version of `remove-duplicates'. |
|---|
| 417 |
|
|---|
| 418 |
- Function: substitute new old seq &key :test :test-not :key :count |
|---|
| 419 |
:start :end :from-end |
|---|
| 420 |
This function returns a copy of SEQ, with all elements matching |
|---|
| 421 |
OLD replaced with NEW. The `:count', `:start', `:end', and |
|---|
| 422 |
`:from-end' arguments may be used to limit the number of |
|---|
| 423 |
substitutions made. |
|---|
| 424 |
|
|---|
| 425 |
- Function: nsubstitute new old seq &key :test :test-not :key :count |
|---|
| 426 |
:start :end :from-end |
|---|
| 427 |
This is a destructive version of `substitute'; it performs the |
|---|
| 428 |
substitution using `setcar' or `aset' rather than by returning a |
|---|
| 429 |
changed copy of the sequence. |
|---|
| 430 |
|
|---|
| 431 |
The `substitute-if', `substitute-if-not', `nsubstitute-if', and |
|---|
| 432 |
`nsubstitute-if-not' functions are defined similarly. For these, a |
|---|
| 433 |
PREDICATE is given in place of the OLD argument. |
|---|
| 434 |
|
|---|
| 435 |
|
|---|
| 436 |
File: cl, Node: Searching Sequences, Next: Sorting Sequences, Prev: Sequence Functions, Up: Sequences |
|---|
| 437 |
|
|---|
| 438 |
Searching Sequences |
|---|
| 439 |
=================== |
|---|
| 440 |
|
|---|
| 441 |
These functions search for elements or subsequences in a sequence. |
|---|
| 442 |
(See also `member*' and `assoc*'; *note Lists::.) |
|---|
| 443 |
|
|---|
| 444 |
- Function: find item seq &key :test :test-not :key :start :end |
|---|
| 445 |
:from-end |
|---|
| 446 |
This function searches SEQ for an element matching ITEM. If it |
|---|
| 447 |
finds a match, it returns the matching element. Otherwise, it |
|---|
| 448 |
returns `nil'. It returns the leftmost match, unless `:from-end' |
|---|
| 449 |
is true, in which case it returns the rightmost match. The |
|---|
| 450 |
`:start' and `:end' arguments may be used to limit the range of |
|---|
| 451 |
elements that are searched. |
|---|
| 452 |
|
|---|
| 453 |
- Function: position item seq &key :test :test-not :key :start :end |
|---|
| 454 |
:from-end |
|---|
| 455 |
This function is like `find', except that it returns the integer |
|---|
| 456 |
position in the sequence of the matching item rather than the item |
|---|
| 457 |
itself. The position is relative to the start of the sequence as |
|---|
| 458 |
a whole, even if `:start' is non-zero. The function returns `nil' |
|---|
| 459 |
if no matching element was found. |
|---|
| 460 |
|
|---|
| 461 |
- Function: count item seq &key :test :test-not :key :start :end |
|---|
| 462 |
This function returns the number of elements of SEQ which match |
|---|
| 463 |
ITEM. The result is always a nonnegative integer. |
|---|
| 464 |
|
|---|
| 465 |
The `find-if', `find-if-not', `position-if', `position-if-not', |
|---|
| 466 |
`count-if', and `count-if-not' functions are defined similarly. |
|---|
| 467 |
|
|---|
| 468 |
- Function: mismatch seq1 seq2 &key :test :test-not :key :start1 :end1 |
|---|
| 469 |
:start2 :end2 :from-end |
|---|
| 470 |
This function compares the specified parts of SEQ1 and SEQ2. If |
|---|
| 471 |
they are the same length and the corresponding elements match |
|---|
| 472 |
(according to `:test', `:test-not', and `:key'), the function |
|---|
| 473 |
returns `nil'. If there is a mismatch, the function returns the |
|---|
| 474 |
index (relative to SEQ1) of the first mismatching element. This |
|---|
| 475 |
will be the leftmost pair of elements which do not match, or the |
|---|
| 476 |
position at which the shorter of the two otherwise-matching |
|---|
| 477 |
sequences runs out. |
|---|
| 478 |
|
|---|
| 479 |
If `:from-end' is true, then the elements are compared from right |
|---|
| 480 |
to left starting at `(1- END1)' and `(1- END2)'. If the sequences |
|---|
| 481 |
differ, then one plus the index of the rightmost difference |
|---|
| 482 |
(relative to SEQ1) is returned. |
|---|
| 483 |
|
|---|
| 484 |
An interesting example is `(mismatch str1 str2 :key 'upcase)', |
|---|
| 485 |
which compares two strings case-insensitively. |
|---|
| 486 |
|
|---|
| 487 |
- Function: search seq1 seq2 &key :test :test-not :key :from-end |
|---|
| 488 |
:start1 :end1 :start2 :end2 |
|---|
| 489 |
This function searches SEQ2 for a subsequence that matches SEQ1 |
|---|
| 490 |
(or part of it specified by `:start1' and `:end1'.) Only matches |
|---|
| 491 |
which fall entirely within the region defined by `:start2' and |
|---|
| 492 |
`:end2' will be considered. The return value is the index of the |
|---|
| 493 |
leftmost element of the leftmost match, relative to the start of |
|---|
| 494 |
SEQ2, or `nil' if no matches were found. If `:from-end' is true, |
|---|
| 495 |
the function finds the _rightmost_ matching subsequence. |
|---|
| 496 |
|
|---|
| 497 |
|
|---|
| 498 |
File: cl, Node: Sorting Sequences, Prev: Searching Sequences, Up: Sequences |
|---|
| 499 |
|
|---|
| 500 |
Sorting Sequences |
|---|
| 501 |
================= |
|---|
| 502 |
|
|---|
| 503 |
- Function: sort* seq predicate &key :key |
|---|
| 504 |
This function sorts SEQ into increasing order as determined by |
|---|
| 505 |
using PREDICATE to compare pairs of elements. PREDICATE should |
|---|
| 506 |
return true (non-`nil') if and only if its first argument is less |
|---|
| 507 |
than (not equal to) its second argument. For example, `<' and |
|---|
| 508 |
`string-lessp' are suitable predicate functions for sorting |
|---|
| 509 |
numbers and strings, respectively; `>' would sort numbers into |
|---|
| 510 |
decreasing rather than increasing order. |
|---|
| 511 |
|
|---|
| 512 |
This function differs from Emacs' built-in `sort' in that it can |
|---|
| 513 |
operate on any type of sequence, not just lists. Also, it accepts |
|---|
| 514 |
a `:key' argument which is used to preprocess data fed to the |
|---|
| 515 |
PREDICATE function. For example, |
|---|
| 516 |
|
|---|
| 517 |
(setq data (sort data 'string-lessp :key 'downcase)) |
|---|
| 518 |
|
|---|
| 519 |
sorts DATA, a sequence of strings, into increasing alphabetical |
|---|
| 520 |
order without regard to case. A `:key' function of `car' would be |
|---|
| 521 |
useful for sorting association lists. |
|---|
| 522 |
|
|---|
| 523 |
The `sort*' function is destructive; it sorts lists by actually |
|---|
| 524 |
rearranging the `cdr' pointers in suitable fashion. |
|---|
| 525 |
|
|---|
| 526 |
- Function: stable-sort seq predicate &key :key |
|---|
| 527 |
This function sorts SEQ "stably", meaning two elements which are |
|---|
| 528 |
equal in terms of PREDICATE are guaranteed not to be rearranged |
|---|
| 529 |
out of their original order by the sort. |
|---|
| 530 |
|
|---|
| 531 |
In practice, `sort*' and `stable-sort' are equivalent in Emacs |
|---|
| 532 |
Lisp because the underlying `sort' function is stable by default. |
|---|
| 533 |
However, this package reserves the right to use non-stable methods |
|---|
| 534 |
for `sort*' in the future. |
|---|
| 535 |
|
|---|
| 536 |
- Function: merge type seq1 seq2 predicate &key :key |
|---|
| 537 |
This function merges two sequences SEQ1 and SEQ2 by interleaving |
|---|
| 538 |
their elements. The result sequence, of type TYPE (in the sense |
|---|
| 539 |
of `concatenate'), has length equal to the sum of the lengths of |
|---|
| 540 |
the two input sequences. The sequences may be modified |
|---|
| 541 |
destructively. Order of elements within SEQ1 and SEQ2 is |
|---|
| 542 |
preserved in the interleaving; elements of the two sequences are |
|---|
| 543 |
compared by PREDICATE (in the sense of `sort') and the lesser |
|---|
| 544 |
element goes first in the result. When elements are equal, those |
|---|
| 545 |
from SEQ1 precede those from SEQ2 in the result. Thus, if SEQ1 |
|---|
| 546 |
and SEQ2 are both sorted according to PREDICATE, then the result |
|---|
| 547 |
will be a merged sequence which is (stably) sorted according to |
|---|
| 548 |
PREDICATE. |
|---|
| 549 |
|
|---|
| 550 |
|
|---|
| 551 |
File: cl, Node: Lists, Next: Structures, Prev: Sequences, Up: Top |
|---|
| 552 |
|
|---|
| 553 |
Lists |
|---|
| 554 |
***** |
|---|
| 555 |
|
|---|
| 556 |
The functions described here operate on lists. |
|---|
| 557 |
|
|---|
| 558 |
* Menu: |
|---|
| 559 |
|
|---|
| 560 |
* List Functions:: `caddr', `first', `list*', etc. |
|---|
| 561 |
* Substitution of Expressions:: `subst', `sublis', etc. |
|---|
| 562 |
* Lists as Sets:: `member*', `adjoin', `union', etc. |
|---|
| 563 |
* Association Lists:: `assoc*', `rassoc*', `acons', `pairlis' |
|---|
| 564 |
|
|---|
| 565 |
|
|---|
| 566 |
File: cl, Node: List Functions, Next: Substitution of Expressions, Prev: Lists, Up: Lists |
|---|
| 567 |
|
|---|
| 568 |
List Functions |
|---|
| 569 |
============== |
|---|
| 570 |
|
|---|
| 571 |
This section describes a number of simple operations on lists, i.e., |
|---|
| 572 |
chains of cons cells. |
|---|
| 573 |
|
|---|
| 574 |
- Function: caddr x |
|---|
| 575 |
This function is equivalent to `(car (cdr (cdr X)))'. Likewise, |
|---|
| 576 |
this package defines all 28 `cXXXr' functions where XXX is up to |
|---|
| 577 |
four `a's and/or `d's. All of these functions are `setf'-able, |
|---|
| 578 |
and calls to them are expanded inline by the byte-compiler for |
|---|
| 579 |
maximum efficiency. |
|---|
| 580 |
|
|---|
| 581 |
- Function: first x |
|---|
| 582 |
This function is a synonym for `(car X)'. Likewise, the functions |
|---|
| 583 |
`second', `third', ..., through `tenth' return the given element |
|---|
| 584 |
of the list X. |
|---|
| 585 |
|
|---|
| 586 |
- Function: rest x |
|---|
| 587 |
This function is a synonym for `(cdr X)'. |
|---|
| 588 |
|
|---|
| 589 |
- Function: endp x |
|---|
| 590 |
Common Lisp defines this function to act like `null', but |
|---|
| 591 |
signaling an error if `x' is neither a `nil' nor a cons cell. |
|---|
| 592 |
This package simply defines `endp' as a synonym for `null'. |
|---|
| 593 |
|
|---|
| 594 |
- Function: list-length x |
|---|
| 595 |
This function returns the length of list X, exactly like `(length |
|---|
| 596 |
X)', except that if X is a circular list (where the cdr-chain |
|---|
| 597 |
forms a loop rather than terminating with `nil'), this function |
|---|
| 598 |
returns `nil'. (The regular `length' function would get stuck if |
|---|
| 599 |
given a circular list.) |
|---|
| 600 |
|
|---|
| 601 |
- Function: list* arg &rest others |
|---|
| 602 |
This function constructs a list of its arguments. The final |
|---|
| 603 |
argument becomes the `cdr' of the last cell constructed. Thus, |
|---|
| 604 |
`(list* A B C)' is equivalent to `(cons A (cons B C))', and |
|---|
| 605 |
`(list* A B nil)' is equivalent to `(list A B)'. |
|---|
| 606 |
|
|---|
| 607 |
(Note that this function really is called `list*' in Common Lisp; |
|---|
| 608 |
it is not a name invented for this package like `member*' or |
|---|
| 609 |
`defun*'.) |
|---|
| 610 |
|
|---|
| 611 |
- Function: ldiff list sublist |
|---|
| 612 |
If SUBLIST is a sublist of LIST, i.e., is `eq' to one of the cons |
|---|
| 613 |
cells of LIST, then this function returns a copy of the part of |
|---|
| 614 |
LIST up to but not including SUBLIST. For example, `(ldiff x |
|---|
| 615 |
(cddr x))' returns the first two elements of the list `x'. The |
|---|
| 616 |
result is a copy; the original LIST is not modified. If SUBLIST |
|---|
| 617 |
is not a sublist of LIST, a copy of the entire LIST is returned. |
|---|
| 618 |
|
|---|
| 619 |
- Function: copy-list list |
|---|
| 620 |
This function returns a copy of the list LIST. It copies dotted |
|---|
| 621 |
lists like `(1 2 . 3)' correctly. |
|---|
| 622 |
|
|---|
| 623 |
- Function: copy-tree x &optional vecp |
|---|
| 624 |
This function returns a copy of the tree of cons cells X. Unlike |
|---|
| 625 |
`copy-sequence' (and its alias `copy-list'), which copies only |
|---|
| 626 |
along the `cdr' direction, this function copies (recursively) |
|---|
| 627 |
along both the `car' and the `cdr' directions. If X is not a cons |
|---|
| 628 |
cell, the function simply returns X unchanged. If the optional |
|---|
| 629 |
VECP argument is true, this function copies vectors (recursively) |
|---|
| 630 |
as well as cons cells. |
|---|
| 631 |
|
|---|
| 632 |
- Function: tree-equal x y &key :test :test-not :key |
|---|
| 633 |
This function compares two trees of cons cells. If X and Y are |
|---|
| 634 |
both cons cells, their `car's and `cdr's are compared recursively. |
|---|
| 635 |
If neither X nor Y is a cons cell, they are compared by `eql', or |
|---|
| 636 |
according to the specified test. The `:key' function, if |
|---|
| 637 |
specified, is applied to the elements of both trees. *Note |
|---|
| 638 |
Sequences::. |
|---|
| 639 |
|
|---|
| 640 |
|
|---|
| 641 |
File: cl, Node: Substitution of Expressions, Next: Lists as Sets, Prev: List Functions, Up: Lists |
|---|
| 642 |
|
|---|
| 643 |
Substitution of Expressions |
|---|
| 644 |
=========================== |
|---|
| 645 |
|
|---|
| 646 |
These functions substitute elements throughout a tree of cons cells. |
|---|
| 647 |
(*Note Sequence Functions::, for the `substitute' function, which works |
|---|
| 648 |
on just the top-level elements of a list.) |
|---|
| 649 |
|
|---|
| 650 |
- Function: subst new old tree &key :test :test-not :key |
|---|
| 651 |
This function substitutes occurrences of OLD with NEW in TREE, a |
|---|
| 652 |
tree of cons cells. It returns a substituted tree, which will be |
|---|
| 653 |
a copy except that it may share storage with the argument TREE in |
|---|
| 654 |
parts where no substitutions occurred. The original TREE is not |
|---|
| 655 |
modified. This function recurses on, and compares against OLD, |
|---|
| 656 |
both `car's and `cdr's of the component cons cells. If OLD is |
|---|
| 657 |
itself a cons cell, then matching cells in the tree are |
|---|
| 658 |
substituted as usual without recursively substituting in that |
|---|
| 659 |
cell. Comparisons with OLD are done according to the specified |
|---|
| 660 |
test (`eql' by default). The `:key' function is applied to the |
|---|
| 661 |
elements of the tree but not to OLD. |
|---|
| 662 |
|
|---|
| 663 |
- Function: nsubst new old tree &key :test :test-not :key |
|---|
| 664 |
This function is like `subst', except that it works by destructive |
|---|
| 665 |
modification (by `setcar' or `setcdr') rather than copying. |
|---|
| 666 |
|
|---|
| 667 |
The `subst-if', `subst-if-not', `nsubst-if', and `nsubst-if-not' |
|---|
| 668 |
functions are defined similarly. |
|---|
| 669 |
|
|---|
| 670 |
- Function: sublis alist tree &key :test :test-not :key |
|---|
| 671 |
This function is like `subst', except that it takes an association |
|---|
| 672 |
list ALIST of OLD-NEW pairs. Each element of the tree (after |
|---|
| 673 |
applying the `:key' function, if any), is compared with the `car's |
|---|
| 674 |
of ALIST; if it matches, it is replaced by the corresponding `cdr'. |
|---|
| 675 |
|
|---|
| 676 |
- Function: nsublis alist tree &key :test :test-not :key |
|---|
| 677 |
This is a destructive version of `sublis'. |
|---|
| 678 |
|
|---|
| 679 |
|
|---|
| 680 |
File: cl, Node: Lists as Sets, Next: Association Lists, Prev: Substitution of Expressions, Up: Lists |
|---|
| 681 |
|
|---|
| 682 |
Lists as Sets |
|---|
| 683 |
============= |
|---|
| 684 |
|
|---|
| 685 |
These functions perform operations on lists which represent sets of |
|---|
| 686 |
elements. |
|---|
| 687 |
|
|---|
| 688 |
- Function: member* item list &key :test :test-not :key |
|---|
| 689 |
This function searches LIST for an element matching ITEM. If a |
|---|
| 690 |
match is found, it returns the cons cell whose `car' was the |
|---|
| 691 |
matching element. Otherwise, it returns `nil'. Elements are |
|---|
| 692 |
compared by `eql' by default; you can use the `:test', |
|---|
| 693 |
`:test-not', and `:key' arguments to modify this behavior. *Note |
|---|
| 694 |
Sequences::. |
|---|
| 695 |
|
|---|
| 696 |
Note that this function's name is suffixed by `*' to avoid the |
|---|
| 697 |
incompatible `member' function defined in Emacs. (That function |
|---|
| 698 |
uses `equal' for comparisons; it is equivalent to `(member* ITEM |
|---|
| 699 |
LIST :test 'equal)'.) |
|---|
| 700 |
|
|---|
| 701 |
The `member-if' and `member-if-not' functions analogously search for |
|---|
| 702 |
elements which satisfy a given predicate. |
|---|
| 703 |
|
|---|
| 704 |
- Function: tailp sublist list |
|---|
| 705 |
This function returns `t' if SUBLIST is a sublist of LIST, i.e., |
|---|
| 706 |
if SUBLIST is `eql' to LIST or to any of its `cdr's. |
|---|
| 707 |
|
|---|
| 708 |
- Function: adjoin item list &key :test :test-not :key |
|---|
| 709 |
This function conses ITEM onto the front of LIST, like `(cons ITEM |
|---|
| 710 |
LIST)', but only if ITEM is not already present on the list (as |
|---|
| 711 |
determined by `member*'). If a `:key' argument is specified, it |
|---|
| 712 |
is applied to ITEM as well as to the elements of LIST during the |
|---|
| 713 |
search, on the reasoning that ITEM is "about" to become part of |
|---|
| 714 |
the list. |
|---|
| 715 |
|
|---|
| 716 |
- Function: union list1 list2 &key :test :test-not :key |
|---|
| 717 |
This function combines two lists which represent sets of items, |
|---|
| 718 |
returning a list that represents the union of those two sets. The |
|---|
| 719 |
result list will contain all items which appear in LIST1 or LIST2, |
|---|
| 720 |
and no others. If an item appears in both LIST1 and LIST2 it will |
|---|
| 721 |
be copied only once. If an item is duplicated in LIST1 or LIST2, |
|---|
| 722 |
it is undefined whether or not that duplication will survive in the |
|---|
| 723 |
result list. The order of elements in the result list is also |
|---|
| 724 |
undefined. |
|---|
| 725 |
|
|---|
| 726 |
- Function: nunion list1 list2 &key :test :test-not :key |
|---|
| 727 |
This is a destructive version of `union'; rather than copying, it |
|---|
| 728 |
tries to reuse the storage of the argument lists if possible. |
|---|
| 729 |
|
|---|
| 730 |
- Function: intersection list1 list2 &key :test :test-not :key |
|---|
| 731 |
This function computes the intersection of the sets represented by |
|---|
| 732 |
LIST1 and LIST2. It returns the list of items which appear in |
|---|
| 733 |
both LIST1 and LIST2. |
|---|
| 734 |
|
|---|
| 735 |
- Function: nintersection list1 list2 &key :test :test-not :key |
|---|
| 736 |
This is a destructive version of `intersection'. It tries to |
|---|
| 737 |
reuse storage of LIST1 rather than copying. It does _not_ reuse |
|---|
| 738 |
the storage of LIST2. |
|---|
| 739 |
|
|---|
| 740 |
- Function: set-difference list1 list2 &key :test :test-not :key |
|---|
| 741 |
This function computes the "set difference" of LIST1 and LIST2, |
|---|
| 742 |
i.e., the set of elements that appear in LIST1 but _not_ in LIST2. |
|---|
| 743 |
|
|---|
| 744 |
- Function: nset-difference list1 list2 &key :test :test-not :key |
|---|
| 745 |
This is a destructive `set-difference', which will try to reuse |
|---|
| 746 |
LIST1 if possible. |
|---|
| 747 |
|
|---|
| 748 |
- Function: set-exclusive-or list1 list2 &key :test :test-not :key |
|---|
| 749 |
This function computes the "set exclusive or" of LIST1 and LIST2, |
|---|
| 750 |
i.e., the set of elements that appear in exactly one of LIST1 and |
|---|
| 751 |
LIST2. |
|---|
| 752 |
|
|---|
| 753 |
- Function: nset-exclusive-or list1 list2 &key :test :test-not :key |
|---|
| 754 |
This is a destructive `set-exclusive-or', which will try to reuse |
|---|
| 755 |
LIST1 and LIST2 if possible. |
|---|
| 756 |
|
|---|
| 757 |
- Function: subsetp list1 list2 &key :test :test-not :key |
|---|
| 758 |
This function checks whether LIST1 represents a subset of LIST2, |
|---|
| 759 |
i.e., whether every element of LIST1 also appears in LIST2. |
|---|
| 760 |
|
|---|
| 761 |
|
|---|
| 762 |
File: cl, Node: Association Lists, Prev: Lists as Sets, Up: Lists |
|---|
| 763 |
|
|---|
| 764 |
Association Lists |
|---|
| 765 |
================= |
|---|
| 766 |
|
|---|
| 767 |
An "association list" is a list representing a mapping from one set of |
|---|
| 768 |
values to another; any list whose elements are cons cells is an |
|---|
| 769 |
association list. |
|---|
| 770 |
|
|---|
| 771 |
- Function: assoc* item a-list &key :test :test-not :key |
|---|
| 772 |
This function searches the association list A-LIST for an element |
|---|
| 773 |
whose `car' matches (in the sense of `:test', `:test-not', and |
|---|
| 774 |
`:key', or by comparison with `eql') a given ITEM. It returns the |
|---|
| 775 |
matching element, if any, otherwise `nil'. It ignores elements of |
|---|
| 776 |
A-LIST which are not cons cells. (This corresponds to the |
|---|
| 777 |
behavior of `assq' and `assoc' in Emacs Lisp; Common Lisp's |
|---|
| 778 |
`assoc' ignores `nil's but considers any other non-cons elements |
|---|
| 779 |
of A-LIST to be an error.) |
|---|
| 780 |
|
|---|
| 781 |
- Function: rassoc* item a-list &key :test :test-not :key |
|---|
| 782 |
This function searches for an element whose `cdr' matches ITEM. |
|---|
| 783 |
If A-LIST represents a mapping, this applies the inverse of the |
|---|
| 784 |
mapping to ITEM. |
|---|
| 785 |
|
|---|
| 786 |
The `assoc-if', `assoc-if-not', `rassoc-if', and `rassoc-if-not' |
|---|
| 787 |
functions are defined similarly. |
|---|
| 788 |
|
|---|
| 789 |
Two simple functions for constructing association lists are: |
|---|
| 790 |
|
|---|
| 791 |
- Function: acons key value alist |
|---|
| 792 |
This is equivalent to `(cons (cons KEY VALUE) ALIST)'. |
|---|
| 793 |
|
|---|
| 794 |
- Function: pairlis keys values &optional alist |
|---|
| 795 |
This is equivalent to `(nconc (mapcar* 'cons KEYS VALUES) ALIST)'. |
|---|
| 796 |
|
|---|