annotate man/lispref/lists.texi @ 5583:10f179710250

Deprecate #'remassoc, #'remassq, #'remrassoc, #'remrassq. src/ChangeLog addition: 2011-10-09 Aidan Kehoe <kehoea@parhasard.net> * fns.c (remassoc_no_quit): * fns.c (remrassq_no_quit): * fns.c (syms_of_fns): * fontcolor-tty.c (Fregister_tty_color): * fontcolor-tty.c (Funregister_tty_color): * fontcolor-tty.c (Ffind_tty_color): * lisp.h: Remove Fremassq, Fremrassq, Fremassoc, Fremrassoc, they're XEmacs-specific functions and Lisp callers should use (delete* ... :key #'car) anyway. Keep the non-Lisp-visible _no_quit versions, calling FdeleteX from C with the appropriate arguments is ungainly. lisp/ChangeLog addition: 2011-10-09 Aidan Kehoe <kehoea@parhasard.net> * obsolete.el: * obsolete.el (assq-delete-all): * packages.el (package-provide): * packages.el (package-suppress): * mule/cyrillic.el ("Cyrillic-KOI8"): * mule/cyrillic.el (koi8-u): * mule/general-late.el (posix-charset-to-coding-system-hash): * mule/latin.el: * mule/latin.el (for): * cl-extra.el: * cl-extra.el (cl-extra): * loadup.el (load-history): Change any uses of #'remassq, #'remassoc and friends to calling #'delete* with an appropriate key argument. Provide compatibility implementations, mark them obsolete. man/ChangeLog addition: 2011-10-09 Aidan Kehoe <kehoea@parhasard.net> * lispref/lists.texi (Association Lists): Don't document #'remassoc, #'remassq and friends in detail; they're XEmacs-specific and (delete* ... :key #'car) is preferable.
author Aidan Kehoe <kehoea@parhasard.net>
date Sun, 09 Oct 2011 12:55:51 +0100
parents 62b9ef1ed4ac
children 9fae6227ede5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 @c -*-texinfo-*-
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 @c This is part of the XEmacs Lisp Reference Manual.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4 @c See the file lispref.texi for copying conditions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 @setfilename ../../info/lists.info
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 @node Lists, Sequences Arrays Vectors, Strings and Characters, Top
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 @chapter Lists
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 @cindex list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 @cindex element (of list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 A @dfn{list} represents a sequence of zero or more elements (which may
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 be any Lisp objects). The important difference between lists and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 vectors is that two or more lists can share part of their structure; in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 addition, you can insert or delete elements in a list without copying
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 the whole list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 @menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 * Cons Cells:: How lists are made out of cons cells.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 * Lists as Boxes:: Graphical notation to explain lists.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 * List-related Predicates:: Is this object a list? Comparing two lists.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 * List Elements:: Extracting the pieces of a list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 * Building Lists:: Creating list structure.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 * Modifying Lists:: Storing new pieces into an existing list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 * Sets And Lists:: A list can represent a finite mathematical set.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 * Association Lists:: A list can represent a finite relation or mapping.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 * Property Lists:: A different way to represent a finite mapping.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 * Weak Lists:: A list with special garbage-collection behavior.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 @end menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 @node Cons Cells
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 @section Lists and Cons Cells
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 @cindex lists and cons cells
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 @cindex @code{nil} and lists
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 Lists in Lisp are not a primitive data type; they are built up from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 @dfn{cons cells}. A cons cell is a data object that represents an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 ordered pair. It records two Lisp objects, one labeled as the @sc{car},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 and the other labeled as the @sc{cdr}. These names are traditional; see
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 @ref{Cons Cell Type}. @sc{cdr} is pronounced ``could-er.''
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 A list is a series of cons cells chained together, one cons cell per
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 element of the list. By convention, the @sc{car}s of the cons cells are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 the elements of the list, and the @sc{cdr}s are used to chain the list:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 the @sc{cdr} of each cons cell is the following cons cell. The @sc{cdr}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 of the last cons cell is @code{nil}. This asymmetry between the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 @sc{car} and the @sc{cdr} is entirely a matter of convention; at the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 level of cons cells, the @sc{car} and @sc{cdr} slots have the same
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 characteristics.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 @cindex list structure
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 Because most cons cells are used as part of lists, the phrase
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 @dfn{list structure} has come to mean any structure made out of cons
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 cells.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 The symbol @code{nil} is considered a list as well as a symbol; it is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 the list with no elements. For convenience, the symbol @code{nil} is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 considered to have @code{nil} as its @sc{cdr} (and also as its
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 @sc{car}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 The @sc{cdr} of any nonempty list @var{l} is a list containing all the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 elements of @var{l} except the first.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 @node Lists as Boxes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 @section Lists as Linked Pairs of Boxes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 @cindex box representation for lists
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 @cindex lists represented as boxes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 @cindex cons cell as box
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 A cons cell can be illustrated as a pair of boxes. The first box
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 represents the @sc{car} and the second box represents the @sc{cdr}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 Here is an illustration of the two-element list, @code{(tulip lily)},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 made from two cons cells:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 --------------- ---------------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 | car | cdr | | car | cdr |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 | tulip | o---------->| lily | nil |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 | | | | | |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 --------------- ---------------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 Each pair of boxes represents a cons cell. Each box ``refers to'',
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 ``points to'' or ``contains'' a Lisp object. (These terms are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 synonymous.) The first box, which is the @sc{car} of the first cons
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 cell, contains the symbol @code{tulip}. The arrow from the @sc{cdr} of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 the first cons cell to the second cons cell indicates that the @sc{cdr}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 of the first cons cell points to the second cons cell.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 The same list can be illustrated in a different sort of box notation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 like this:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 ___ ___ ___ ___
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 |___|___|--> |___|___|--> nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 | |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 | |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 --> tulip --> lily
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 Here is a more complex illustration, showing the three-element list,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 @code{((pine needles) oak maple)}, the first element of which is a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 two-element list:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 ___ ___ ___ ___ ___ ___
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 |___|___|--> |___|___|--> |___|___|--> nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 | | |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 | | |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 | --> oak --> maple
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 | ___ ___ ___ ___
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 --> |___|___|--> |___|___|--> nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 | |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 | |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 --> pine --> needles
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 The same list represented in the first box notation looks like this:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 -------------- -------------- --------------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 | car | cdr | | car | cdr | | car | cdr |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 | o | o------->| oak | o------->| maple | nil |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 | | | | | | | | | |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 -- | --------- -------------- --------------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 | -------------- ----------------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 | | car | cdr | | car | cdr |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 ------>| pine | o------->| needles | nil |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 | | | | | |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 -------------- ----------------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 @xref{Cons Cell Type}, for the read and print syntax of cons cells and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 lists, and for more ``box and arrow'' illustrations of lists.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 @node List-related Predicates
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 @section Predicates on Lists
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 The following predicates test whether a Lisp object is an atom, is a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 cons cell or is a list, or whether it is the distinguished object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 @code{nil}. (Many of these predicates can be defined in terms of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 others, but they are used so often that it is worth having all of them.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 @defun consp object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 This function returns @code{t} if @var{object} is a cons cell, @code{nil}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 otherwise. @code{nil} is not a cons cell, although it @emph{is} a list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 @defun atom object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 @cindex atoms
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 This function returns @code{t} if @var{object} is an atom, @code{nil}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 otherwise. All objects except cons cells are atoms. The symbol
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 @code{nil} is an atom and is also a list; it is the only Lisp object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 that is both.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 (atom @var{object}) @equiv{} (not (consp @var{object}))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 @defun listp object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 This function returns @code{t} if @var{object} is a cons cell or
1549
bc9eadea35cf [xemacs-hg @ 2003-06-30 09:30:58 by stephent]
stephent
parents: 444
diff changeset
173 @code{nil}. Otherwise, it returns @code{nil}. @code{true-list-p} is
bc9eadea35cf [xemacs-hg @ 2003-06-30 09:30:58 by stephent]
stephent
parents: 444
diff changeset
174 slower, but in some circumstances it is more appropriate.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 (listp '(1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 @result{} t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 (listp '())
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 @result{} t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 @defun nlistp object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 This function is the opposite of @code{listp}: it returns @code{t} if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 @var{object} is not a list. Otherwise, it returns @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 (listp @var{object}) @equiv{} (not (nlistp @var{object}))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196
1549
bc9eadea35cf [xemacs-hg @ 2003-06-30 09:30:58 by stephent]
stephent
parents: 444
diff changeset
197 @defun true-list-p object
bc9eadea35cf [xemacs-hg @ 2003-06-30 09:30:58 by stephent]
stephent
parents: 444
diff changeset
198 This function returns @code{t} if @var{object} is an acyclic,
bc9eadea35cf [xemacs-hg @ 2003-06-30 09:30:58 by stephent]
stephent
parents: 444
diff changeset
199 @code{nil}-terminated (ie, not dotted), list. Otherwise it returns
bc9eadea35cf [xemacs-hg @ 2003-06-30 09:30:58 by stephent]
stephent
parents: 444
diff changeset
200 @code{nil}. @code{listp} is faster.
1554
b880e7bdec21 [xemacs-hg @ 2003-07-01 04:33:43 by stephent]
stephent
parents: 1549
diff changeset
201 @end defun
1549
bc9eadea35cf [xemacs-hg @ 2003-06-30 09:30:58 by stephent]
stephent
parents: 444
diff changeset
202
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 @defun null object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 This function returns @code{t} if @var{object} is @code{nil}, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 returns @code{nil} otherwise. This function is identical to @code{not},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 but as a matter of clarity we use @code{null} when @var{object} is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 considered a list and @code{not} when it is considered a truth value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 (see @code{not} in @ref{Combining Conditions}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 (null '(1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 @result{} nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 (null '())
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 @result{} t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 @need 2000
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 @node List Elements
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 @section Accessing Elements of Lists
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 @cindex list elements
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 @defun car cons-cell
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 This function returns the value pointed to by the first pointer of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 cons cell @var{cons-cell}. Expressed another way, this function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 returns the @sc{car} of @var{cons-cell}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 As a special case, if @var{cons-cell} is @code{nil}, then @code{car}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 is defined to return @code{nil}; therefore, any list is a valid argument
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 for @code{car}. An error is signaled if the argument is not a cons cell
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 or @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 (car '(a b c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 @result{} a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 (car '())
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 @result{} nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 @defun cdr cons-cell
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 This function returns the value pointed to by the second pointer of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 the cons cell @var{cons-cell}. Expressed another way, this function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 returns the @sc{cdr} of @var{cons-cell}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 As a special case, if @var{cons-cell} is @code{nil}, then @code{cdr}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 is defined to return @code{nil}; therefore, any list is a valid argument
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 for @code{cdr}. An error is signaled if the argument is not a cons cell
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 or @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 (cdr '(a b c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 @result{} (b c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 (cdr '())
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 @result{} nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 @defun car-safe object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 This function lets you take the @sc{car} of a cons cell while avoiding
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 errors for other data types. It returns the @sc{car} of @var{object} if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 @var{object} is a cons cell, @code{nil} otherwise. This is in contrast
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 to @code{car}, which signals an error if @var{object} is not a list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 (car-safe @var{object})
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 @equiv{}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 (let ((x @var{object}))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 (if (consp x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 (car x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 @defun cdr-safe object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 This function lets you take the @sc{cdr} of a cons cell while
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 avoiding errors for other data types. It returns the @sc{cdr} of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 @var{object} if @var{object} is a cons cell, @code{nil} otherwise.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 This is in contrast to @code{cdr}, which signals an error if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 @var{object} is not a list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 (cdr-safe @var{object})
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 @equiv{}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 (let ((x @var{object}))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 (if (consp x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 (cdr x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 @defun nth n list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 This function returns the @var{n}th element of @var{list}. Elements
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 are numbered starting with zero, so the @sc{car} of @var{list} is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 element number zero. If the length of @var{list} is @var{n} or less,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 the value is @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 If @var{n} is negative, @code{nth} returns the first element of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 @var{list}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 (nth 2 '(1 2 3 4))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 @result{} 3
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 (nth 10 '(1 2 3 4))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 @result{} nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 (nth -3 '(1 2 3 4))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 @result{} 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 (nth n x) @equiv{} (car (nthcdr n x))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 @defun nthcdr n list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 This function returns the @var{n}th @sc{cdr} of @var{list}. In other
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 words, it removes the first @var{n} links of @var{list} and returns
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 what follows.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 If @var{n} is zero or negative, @code{nthcdr} returns all of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 @var{list}. If the length of @var{list} is @var{n} or less,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 @code{nthcdr} returns @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 (nthcdr 1 '(1 2 3 4))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 @result{} (2 3 4)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 (nthcdr 10 '(1 2 3 4))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 @result{} nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 (nthcdr -3 '(1 2 3 4))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 @result{} (1 2 3 4)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 Many convenience functions are provided to make it easier for you to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 access particular elements in a nested list. All of these can be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 rewritten in terms of the functions just described.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 @defun caar cons-cell
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 @defunx cadr cons-cell
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 @defunx cdar cons-cell
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 @defunx cddr cons-cell
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 @defunx caaar cons-cell
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 @defunx caadr cons-cell
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 @defunx cadar cons-cell
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 @defunx caddr cons-cell
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 @defunx cdaar cons-cell
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 @defunx cdadr cons-cell
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 @defunx cddar cons-cell
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 @defunx cdddr cons-cell
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 @defunx caaaar cons-cell
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 @defunx caaadr cons-cell
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 @defunx caadar cons-cell
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 @defunx caaddr cons-cell
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 @defunx cadaar cons-cell
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 @defunx cadadr cons-cell
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 @defunx caddar cons-cell
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 @defunx cadddr cons-cell
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 @defunx cdaaar cons-cell
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 @defunx cdaadr cons-cell
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 @defunx cdadar cons-cell
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 @defunx cdaddr cons-cell
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 @defunx cddaar cons-cell
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 @defunx cddadr cons-cell
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 @defunx cdddar cons-cell
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 @defunx cddddr cons-cell
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 Each of these functions is equivalent to one or more applications of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 @code{car} and/or @code{cdr}. For example,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 (cadr x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 is equivalent to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 (car (cdr x))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 (cdaddr x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 is equivalent to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 (cdr (car (cdr (cdr x))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 That is to say, read the a's and d's from right to left and apply
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 a @code{car} or @code{cdr} for each a or d found, respectively.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 @defun first list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 This is equivalent to @code{(nth 0 @var{list})}, i.e. the first element
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 of @var{list}. (Note that this is also equivalent to @code{car}.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 @defun second list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 This is equivalent to @code{(nth 1 @var{list})}, i.e. the second element
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 of @var{list}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 @defun third list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 @defunx fourth list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 @defunx fifth list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 @defunx sixth list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 @defunx seventh list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 @defunx eighth list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 @defunx ninth list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 @defunx tenth list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 These are equivalent to @code{(nth 2 @var{list})} through
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 @code{(nth 9 @var{list})} respectively, i.e. the third through tenth
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 elements of @var{list}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 @node Building Lists
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 @section Building Cons Cells and Lists
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 @cindex cons cells
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 @cindex building lists
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 Many functions build lists, as lists reside at the very heart of Lisp.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 @code{cons} is the fundamental list-building function; however, it is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 interesting to note that @code{list} is used more times in the source
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 code for Emacs than @code{cons}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 @defun cons object1 object2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 This function is the fundamental function used to build new list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 structure. It creates a new cons cell, making @var{object1} the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 @sc{car}, and @var{object2} the @sc{cdr}. It then returns the new cons
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 cell. The arguments @var{object1} and @var{object2} may be any Lisp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 objects, but most often @var{object2} is a list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 (cons 1 '(2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 @result{} (1 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 (cons 1 '())
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 @result{} (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 (cons 1 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 @result{} (1 . 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 @cindex consing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 @code{cons} is often used to add a single element to the front of a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 list. This is called @dfn{consing the element onto the list}. For
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 example:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 (setq list (cons newelt list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 Note that there is no conflict between the variable named @code{list}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 used in this example and the function named @code{list} described below;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 any symbol can serve both purposes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 @defun list &rest objects
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 This function creates a list with @var{objects} as its elements. The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 resulting list is always @code{nil}-terminated. If no @var{objects}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 are given, the empty list is returned.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 (list 1 2 3 4 5)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 @result{} (1 2 3 4 5)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 (list 1 2 '(3 4 5) 'foo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 @result{} (1 2 (3 4 5) foo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 (list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 @result{} nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 @defun make-list length object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 This function creates a list of length @var{length}, in which all the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 elements have the identical value @var{object}. Compare
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 @code{make-list} with @code{make-string} (@pxref{Creating Strings}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 (make-list 3 'pigs)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 @result{} (pigs pigs pigs)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 (make-list 0 'pigs)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 @result{} nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 @defun append &rest sequences
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 @cindex copying lists
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 This function returns a list containing all the elements of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 @var{sequences}. The @var{sequences} may be lists, vectors, or strings,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 but the last one should be a list. All arguments except the last one
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 are copied, so none of them are altered.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 More generally, the final argument to @code{append} may be any Lisp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 object. The final argument is not copied or converted; it becomes the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 @sc{cdr} of the last cons cell in the new list. If the final argument
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 is itself a list, then its elements become in effect elements of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 result list. If the final element is not a list, the result is a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 ``dotted list'' since its final @sc{cdr} is not @code{nil} as required
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 in a true list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 See @code{nconc} in @ref{Rearrangement}, for a way to join lists with no
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 copying.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 Here is an example of using @code{append}:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 (setq trees '(pine oak))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 @result{} (pine oak)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 (setq more-trees (append '(maple birch) trees))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 @result{} (maple birch pine oak)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 trees
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 @result{} (pine oak)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 more-trees
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 @result{} (maple birch pine oak)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 (eq trees (cdr (cdr more-trees)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 @result{} t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569 You can see how @code{append} works by looking at a box diagram. The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 variable @code{trees} is set to the list @code{(pine oak)} and then the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 variable @code{more-trees} is set to the list @code{(maple birch pine
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 oak)}. However, the variable @code{trees} continues to refer to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 original list:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 more-trees trees
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 | |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 | ___ ___ ___ ___ -> ___ ___ ___ ___
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580 --> |___|___|--> |___|___|--> |___|___|--> |___|___|--> nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 | | | |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582 | | | |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 --> maple -->birch --> pine --> oak
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 An empty sequence contributes nothing to the value returned by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 @code{append}. As a consequence of this, a final @code{nil} argument
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 forces a copy of the previous argument.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 trees
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594 @result{} (pine oak)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 (setq wood (append trees ()))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 @result{} (pine oak)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 wood
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 @result{} (pine oak)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 (eq wood trees)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 @result{} nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 This once was the usual way to copy a list, before the function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 @code{copy-sequence} was invented. @xref{Sequences Arrays Vectors}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614 With the help of @code{apply}, we can append all the lists in a list of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 lists:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 (apply 'append '((a b c) nil (x y z) nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 @result{} (a b c x y z)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 If no @var{sequences} are given, @code{nil} is returned:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628 (append)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 @result{} nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633 Here are some examples where the final argument is not a list:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 (append '(x y) 'z)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 @result{} (x y . z)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 (append '(x y) [z])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 @result{} (x y . [z])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 The second example shows that when the final argument is a sequence but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 not a list, the sequence's elements do not become elements of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 resulting list. Instead, the sequence becomes the final @sc{cdr}, like
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 any other non-list final argument.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648 The @code{append} function also allows integers as arguments. It
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 converts them to strings of digits, making up the decimal print
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 representation of the integer, and then uses the strings instead of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 original integers. @strong{Don't use this feature; we plan to eliminate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 it. If you already use this feature, change your programs now!} The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 proper way to convert an integer to a decimal number in this way is with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 @code{format} (@pxref{Formatting Strings}) or @code{number-to-string}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655 (@pxref{String Conversion}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657
5300
9f738305f80f Accept sequences generally, not just lists, #'reverse, #'nreverse.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5182
diff changeset
658 @defun reverse sequence
9f738305f80f Accept sequences generally, not just lists, #'reverse, #'nreverse.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5182
diff changeset
659 This function creates a new sequence whose elements are the elements of
9f738305f80f Accept sequences generally, not just lists, #'reverse, #'nreverse.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5182
diff changeset
660 @var{sequence}, but in reverse order. The original argument @var{sequence} is
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 @emph{not} altered.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665 (setq x '(1 2 3 4))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 @result{} (1 2 3 4)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 (reverse x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 @result{} (4 3 2 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671 x
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 @result{} (1 2 3 4)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677 @node Modifying Lists
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 @section Modifying Existing List Structure
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 You can modify the @sc{car} and @sc{cdr} contents of a cons cell with the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681 primitives @code{setcar} and @code{setcdr}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 @cindex CL note---@code{rplaca} vrs @code{setcar}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 @quotation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 @findex rplaca
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 @findex rplacd
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 @b{Common Lisp note:} Common Lisp uses functions @code{rplaca} and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 @code{rplacd} to alter list structure; they change structure the same
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689 way as @code{setcar} and @code{setcdr}, but the Common Lisp functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 return the cons cell while @code{setcar} and @code{setcdr} return the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691 new @sc{car} or @sc{cdr}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 @end quotation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 @menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 * Setcar:: Replacing an element in a list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 * Setcdr:: Replacing part of the list backbone.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 This can be used to remove or add elements.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 * Rearrangement:: Reordering the elements in a list; combining lists.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 @end menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701 @node Setcar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702 @subsection Altering List Elements with @code{setcar}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 Changing the @sc{car} of a cons cell is done with @code{setcar}. When
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705 used on a list, @code{setcar} replaces one element of a list with a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 different element.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
708 @defun setcar cons-cell object
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
709 This function stores @var{object} as the new @sc{car} of @var{cons-cell},
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710 replacing its previous @sc{car}. It returns the value @var{object}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711 For example:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 (setq x '(1 2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716 @result{} (1 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719 (setcar x 4)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720 @result{} 4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723 x
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724 @result{} (4 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729 When a cons cell is part of the shared structure of several lists,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 storing a new @sc{car} into the cons changes one element of each of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 these lists. Here is an example:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 ;; @r{Create two lists that are partly shared.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736 (setq x1 '(a b c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 @result{} (a b c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 (setq x2 (cons 'z (cdr x1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739 @result{} (z b c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 ;; @r{Replace the @sc{car} of a shared link.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 (setcar (cdr x1) 'foo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 @result{} foo
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746 x1 ; @r{Both lists are changed.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747 @result{} (a foo c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 x2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749 @result{} (z foo c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 ;; @r{Replace the @sc{car} of a link that is not shared.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 (setcar x1 'baz)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 @result{} baz
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756 x1 ; @r{Only one list is changed.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757 @result{} (baz foo c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 x2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759 @result{} (z foo c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763 Here is a graphical depiction of the shared structure of the two lists
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 in the variables @code{x1} and @code{x2}, showing why replacing @code{b}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765 changes them both:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 ___ ___ ___ ___ ___ ___
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 x1---> |___|___|----> |___|___|--> |___|___|--> nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 | --> | |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 | | | |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 --> a | --> b --> c
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 ___ ___ |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 x2--> |___|___|--
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778 |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779 --> z
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 Here is an alternative form of box diagram, showing the same relationship:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787 x1:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 -------------- -------------- --------------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789 | car | cdr | | car | cdr | | car | cdr |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790 | a | o------->| b | o------->| c | nil |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791 | | | -->| | | | | |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792 -------------- | -------------- --------------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793 |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 x2: |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 -------------- |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796 | car | cdr | |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 | z | o----
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 | | |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 --------------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 @node Setcdr
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 @subsection Altering the CDR of a List
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 The lowest-level primitive for modifying a @sc{cdr} is @code{setcdr}:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
808 @defun setcdr cons-cell object
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
809 This function stores @var{object} as the new @sc{cdr} of @var{cons-cell},
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 replacing its previous @sc{cdr}. It returns the value @var{object}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813 Here is an example of replacing the @sc{cdr} of a list with a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814 different list. All but the first element of the list are removed in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815 favor of a different sequence of elements. The first element is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816 unchanged, because it resides in the @sc{car} of the list, and is not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 reached via the @sc{cdr}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821 (setq x '(1 2 3))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822 @result{} (1 2 3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825 (setcdr x '(4))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826 @result{} (4)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 x
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 @result{} (1 4)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 You can delete elements from the middle of a list by altering the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835 @sc{cdr}s of the cons cells in the list. For example, here we delete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836 the second element, @code{b}, from the list @code{(a b c)}, by changing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837 the @sc{cdr} of the first cell:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 (setq x1 '(a b c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842 @result{} (a b c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843 (setcdr x1 (cdr (cdr x1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844 @result{} (c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845 x1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846 @result{} (a c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 @need 4000
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851 Here is the result in box notation:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855 --------------------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856 | |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857 -------------- | -------------- | --------------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858 | car | cdr | | | car | cdr | -->| car | cdr |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859 | a | o----- | b | o-------->| c | nil |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860 | | | | | | | | |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861 -------------- -------------- --------------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866 The second cons cell, which previously held the element @code{b}, still
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867 exists and its @sc{car} is still @code{b}, but it no longer forms part
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
868 of this list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870 It is equally easy to insert a new element by changing @sc{cdr}s:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874 (setq x1 '(a b c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875 @result{} (a b c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876 (setcdr x1 (cons 'd (cdr x1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
877 @result{} (d b c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878 x1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879 @result{} (a d b c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883 Here is this result in box notation:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887 -------------- ------------- -------------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888 | car | cdr | | car | cdr | | car | cdr |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
889 | a | o | -->| b | o------->| c | nil |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 | | | | | | | | | | |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891 --------- | -- | ------------- -------------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892 | |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893 ----- --------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
894 | |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895 | --------------- |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896 | | car | cdr | |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 -->| d | o------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898 | | |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899 ---------------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
900 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903 @node Rearrangement
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 @subsection Functions that Rearrange Lists
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905 @cindex rearrangement of lists
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906 @cindex modification of lists
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908 Here are some functions that rearrange lists ``destructively'' by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909 modifying the @sc{cdr}s of their component cons cells. We call these
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910 functions ``destructive'' because they chew up the original lists passed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911 to them as arguments, to produce a new list that is the returned value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913 @ifinfo
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914 See @code{delq}, in @ref{Sets And Lists}, for another function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915 that modifies cons cells.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916 @end ifinfo
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917 @iftex
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918 The function @code{delq} in the following section is another example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919 of destructive list manipulation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
920 @end iftex
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
922 @defun nconc &rest lists
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
923 @cindex concatenating lists
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924 @cindex joining lists
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925 This function returns a list containing all the elements of @var{lists}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926 Unlike @code{append} (@pxref{Building Lists}), the @var{lists} are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927 @emph{not} copied. Instead, the last @sc{cdr} of each of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928 @var{lists} is changed to refer to the following list. The last of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929 @var{lists} is not altered. For example:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
932 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933 (setq x '(1 2 3))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934 @result{} (1 2 3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
936 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937 (nconc x '(4 5))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938 @result{} (1 2 3 4 5)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
941 x
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
942 @result{} (1 2 3 4 5)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
944 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946 Since the last argument of @code{nconc} is not itself modified, it is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947 reasonable to use a constant list, such as @code{'(4 5)}, as in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948 above example. For the same reason, the last argument need not be a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
949 list:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
950
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
951 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
952 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
953 (setq x '(1 2 3))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
954 @result{} (1 2 3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
955 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
956 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
957 (nconc x 'z)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
958 @result{} (1 2 3 . z)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
960 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
961 x
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
962 @result{} (1 2 3 . z)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
963 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
964 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
965
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
966 A common pitfall is to use a quoted constant list as a non-last
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
967 argument to @code{nconc}. If you do this, your program will change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
968 each time you run it! Here is what happens:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
969
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
970 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
971 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972 (defun add-foo (x) ; @r{We want this function to add}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973 (nconc '(foo) x)) ; @r{@code{foo} to the front of its arg.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
974 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
975
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
976 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
977 (symbol-function 'add-foo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978 @result{} (lambda (x) (nconc (quote (foo)) x))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
979 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
980
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
981 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
982 (setq xx (add-foo '(1 2))) ; @r{It seems to work.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
983 @result{} (foo 1 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
984 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
985 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
986 (setq xy (add-foo '(3 4))) ; @r{What happened?}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
987 @result{} (foo 1 2 3 4)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
988 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
989 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
990 (eq xx xy)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
991 @result{} t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
992 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
993
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
994 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
995 (symbol-function 'add-foo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
996 @result{} (lambda (x) (nconc (quote (foo 1 2 3 4) x)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
997 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
998 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
999 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1000
5300
9f738305f80f Accept sequences generally, not just lists, #'reverse, #'nreverse.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5182
diff changeset
1001 @defun nreverse sequence
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1002 @cindex reversing a list
5300
9f738305f80f Accept sequences generally, not just lists, #'reverse, #'nreverse.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5182
diff changeset
1003 @cindex reversing a sequence
9f738305f80f Accept sequences generally, not just lists, #'reverse, #'nreverse.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5182
diff changeset
1004 This function reverses the order of the elements of @var{sequence}.
9f738305f80f Accept sequences generally, not just lists, #'reverse, #'nreverse.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5182
diff changeset
1005 Unlike @code{reverse}, @code{nreverse} alters its argument. If
9f738305f80f Accept sequences generally, not just lists, #'reverse, #'nreverse.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5182
diff changeset
1006 @var{sequence} is a list, it does this by reversing the @sc{cdr}s in the
9f738305f80f Accept sequences generally, not just lists, #'reverse, #'nreverse.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5182
diff changeset
1007 cons cells forming the sequence. The cons cell that used to be the last
9f738305f80f Accept sequences generally, not just lists, #'reverse, #'nreverse.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5182
diff changeset
1008 one in @var{sequence} becomes the first cell of the value.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1009
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1010 For example:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1011
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1012 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1013 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1014 (setq x '(1 2 3 4))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1015 @result{} (1 2 3 4)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1016 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1017 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1018 x
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1019 @result{} (1 2 3 4)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1020 (nreverse x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1021 @result{} (4 3 2 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1022 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1023 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1024 ;; @r{The cell that was first is now last.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1025 x
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1026 @result{} (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1027 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1028 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1029
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1030 To avoid confusion, we usually store the result of @code{nreverse}
5300
9f738305f80f Accept sequences generally, not just lists, #'reverse, #'nreverse.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5182
diff changeset
1031 back in the same variable which held the original sequence:
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1032
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1033 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1034 (setq x (nreverse x))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1035 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1036
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1037 Here is the @code{nreverse} of our favorite example, @code{(a b c)},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1038 presented graphically:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1039
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1040 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1041 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1042 @r{Original list head:} @r{Reversed list:}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1043 ------------- ------------- ------------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1044 | car | cdr | | car | cdr | | car | cdr |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1045 | a | nil |<-- | b | o |<-- | c | o |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1046 | | | | | | | | | | | | |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1047 ------------- | --------- | - | -------- | -
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1048 | | | |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1049 ------------- ------------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1050 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1051 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1052 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1053
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1554
diff changeset
1054 @defun sort* sequence predicate &key (key #'identity)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1055 @cindex stable sort
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1056 @cindex sorting lists
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1554
diff changeset
1057 @cindex sorting arrays
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1554
diff changeset
1058 @cindex sort
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1554
diff changeset
1059 This function sorts @var{sequence} stably, though destructively, and
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1554
diff changeset
1060 returns the sorted sequence. It compares elements using @var{predicate}. A
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1061 stable sort is one in which elements with equal sort keys maintain their
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1062 relative order before and after the sort. Stability is important when
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1063 successive sorts are used to order elements according to different
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1064 criteria.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1065
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1554
diff changeset
1066 @var{sequence} can be any sequence, that is, a list, a vector, a
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1554
diff changeset
1067 bit-vector, or a string.
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1554
diff changeset
1068
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1069 The argument @var{predicate} must be a function that accepts two
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1554
diff changeset
1070 arguments. It is called with two elements of @var{sequence}. To get an
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1071 increasing order sort, the @var{predicate} should return @code{t} if the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1072 first element is ``less than'' the second, or @code{nil} if not.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1073
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1554
diff changeset
1074 The keyword argument @var{key}, if supplied, is a function used to
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1554
diff changeset
1075 extract an object to be used for comparison from each element of
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1554
diff changeset
1076 @var{sequence}, and defaults to @code{identity}. For example, to sort a
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1554
diff changeset
1077 vector of lists by the numeric value of the first element, you could use
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1554
diff changeset
1078 the following code:
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1554
diff changeset
1079
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1554
diff changeset
1080 @example
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1554
diff changeset
1081 @group
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1554
diff changeset
1082 (setq example-vector [(1 "foo") (3.14159 bar) (2 . quux)])
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1554
diff changeset
1083 @result{} [(1 "foo") (3.14159 bar) (2 . quux)]
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1554
diff changeset
1084 @end group
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1554
diff changeset
1085 @group
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1554
diff changeset
1086 (sort* example-vector #'< :key #'car)
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1554
diff changeset
1087 @result{} [(1 "foo") (2 . quux) (3.14159 bar)]
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1554
diff changeset
1088 @end group
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1554
diff changeset
1089 @end example
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1554
diff changeset
1090
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1554
diff changeset
1091 If @var{sequence} is a list, @code{sort*} rearranges the cons cells
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1554
diff changeset
1092 forming @var{sequence} by changing @sc{cdr}s. A nondestructive sort
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1093 function would create new cons cells to store the elements in their
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1554
diff changeset
1094 sorted order. @code{sort*} treats other sequence types in an analogous
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1554
diff changeset
1095 fashion---if you wish to make a sorted copy without destroying the
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1096 original, copy it first with @code{copy-sequence} and then sort.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1097
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1554
diff changeset
1098 Sorting will not change the @sc{car}s of the cons cells of a list
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1554
diff changeset
1099 @var{sequence}; the cons cell that originally contained the element @code{a} in
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1554
diff changeset
1100 @var{sequence} still has @code{a} in its @sc{car} after sorting, but it now
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1554
diff changeset
1101 appears in a different position in the sequence due to the change of
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1102 @sc{cdr}s. For example:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1103
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1104 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1105 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1106 (setq nums '(1 3 2 6 5 4 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1107 @result{} (1 3 2 6 5 4 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1108 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1109 @group
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1554
diff changeset
1110 (sort* nums '<)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1111 @result{} (0 1 2 3 4 5 6)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1112 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1113 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1114 nums
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1115 @result{} (1 2 3 4 5 6)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1116 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1117 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1118
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1119 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1120 Note that the list in @code{nums} no longer contains 0; this is the same
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1121 cons cell that it was before, but it is no longer the first one in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1122 list. Don't assume a variable that formerly held the argument now holds
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1554
diff changeset
1123 the entire sorted list! Instead, save the result of @code{sort*} and use
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1124 that. Most often we store the result back into the variable that held
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1554
diff changeset
1125 the original sequence:
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1126
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1127 @example
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1554
diff changeset
1128 (setq nums (sort* nums '<))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1129 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1130
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1554
diff changeset
1131 In this implementation, @code{sort} is a function alias for
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1554
diff changeset
1132 @code{sort*}, and accepts the same arguments. In older XEmacs, and in
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1554
diff changeset
1133 current GNU Emacs, @code{sort} only accepted lists, and did not accept
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1554
diff changeset
1134 the @var{key} argument, so the byte-compiler will warn you if you call
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1554
diff changeset
1135 @code{sort} with more than two arguments.
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1554
diff changeset
1136
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1137 @xref{Sorting}, for more functions that perform sorting.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1138 See @code{documentation} in @ref{Accessing Documentation}, for a
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1554
diff changeset
1139 useful example of @code{sort*}.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1140 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1141
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1142 @node Sets And Lists
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1143 @section Using Lists as Sets
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1144 @cindex lists as sets
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1145 @cindex sets
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1146
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1147 A list can represent an unordered mathematical set---simply consider a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1148 value an element of a set if it appears in the list, and ignore the
5359
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1149 order of the list. XEmacs provides set operations inherited from Common
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1150 Lisp.
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1151
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1152 @defun member* item list @t{&key :test :test-not :key}
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1153 This function tests to see whether @var{item} is a member of @var{list},
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1154 comparing with @code{eql}. If it is, @code{member*} returns the tail of
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1155 @var{list} starting with the first occurrence of @var{item}. Otherwise,
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1156 it returns @code{nil}.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1157
5359
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1158 This is equivalent to the Common Lisp @code{member} function, but that
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1159 name was already taken in Emacs Lisp, whence the asterisk at the end of
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1160 @code{member*}.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1161
5359
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1162 The @code{:test} keyword argument allows you to specify the test used to
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1163 decide whether @var{item} is equivalent to a given element of
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1164 @var{list}. The function should return non-@code{nil} if the items
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1165 match, @code{nil} if they do not. The @code{:test-not} keyword is
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1166 similar, but the meaning of @code{nil} and non-@code{nil} results are
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1167 reversed. The @code{:key} keyword allows you to examine a component of
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1168 each object in @var{list}, rather than the object itself.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1169
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1170 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1171 @group
5359
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1172 (member* 'b '(a b c b a))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1173 @result{} (b c b a)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1174 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1175 @group
5359
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1176 (member* '(2) '((1) (2))) ; @r{@code{(2)} and @code{(2)} are not @code{eql}.}
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1177 @result{} nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1178 @end group
5359
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1179 @group
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1180 (member* '(2) '((1) (2)) :test #'equal) ; @r{but they are @code{equal}.}
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1181 @result{} ((2))
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1182 @end group
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1183 @group
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1184 (member* 3 '((1) (2) (3) (4)) :key 'car) ; @r{key not applied to @var{item}}
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1185 @result{} ((3) (4))
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1186 @end group
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1187 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1188 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1189
5359
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1190 @defun memq item list
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1191 This is equivalent to calling @code{(member* item list :test 'eq)}, but
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1192 for historical reasons is more common in the XEmacs code base. Both
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1193 expressions compile to the same byte-code.
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1194 @end defun
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1195
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1196 @defun member item list
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1197 This is equivalent to calling @code{(member* item list :test 'equal)}.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1198 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1199
5359
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1200 @defun remove* item sequence @t{&key (test #'eql) (key #'identity) (start 0) (end (length sequence)) from-end count test-not}
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1201 @cindex removal of elements
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1202
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1203 This function removes all occurrences of @var{object} from
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1204 @var{sequence}, which can be a list, vector, or bit-vector.
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1205
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1206 The @code{:test} keyword argument allows you to specify the test used to
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1207 decide whether @var{item} is equivalent to a given element of
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1208 @var{sequence}. The function should return non-@code{nil} if the items
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1209 match, @code{nil} if they do not. The @code{:test-not} keyword is
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1210 similar, but the meaning of @code{nil} and non-@code{nil} results are
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1211 reversed. The @code{:key} keyword allows you to examine a component of
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1212 each object in @var{sequence}, rather than the object itself.
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1213
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1214 The @code{:start} and @code{:end} keywords allow you to specify a
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1215 zero-based subrange of @var{sequence} to operate on, @code{remove*} will
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1216 call the test function on all items of @var{sequence} between the index
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1217 specified by @code{:start}, inclusive, and @code{:end},
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1218 exclusive. @code{:count} gives a maximum number of items to remove, and
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1219 @code{:from-end}, most useful in combination with @code{:count},
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1220 specifies that the removal should start from the end of @var{sequence}.
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1221
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1222 As with @code{member*}, this function is equivalent to the Common Lisp
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1223 function of almost the same name (the Common Lisp function has no
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1224 asterisk.)
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1225
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1226 When @code{remove*} removes elements from the front of a list
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1227 @var{sequence}, it does so simply by advancing down the list and
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1228 returning a sublist that starts after those elements:
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1229
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1230 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1231 @group
5359
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1232 (remove* 'a '(a b c)) @equiv{} (cdr '(a b c))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1233 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1234 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1235
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1236 When an element to be deleted appears in the middle of the list,
5359
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1237 removing it involves copying the list conses up to that point, and
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1238 setting the tail of the copied list to the tail of the original list
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1239 past that point.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1240
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1241 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1242 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1243 (setq sample-list '(a b c (4)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1244 @result{} (a b c (4))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1245 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1246 @group
5359
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1247 (remove* 'a sample-list)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1248 @result{} (b c (4))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1249 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1250 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1251 sample-list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1252 @result{} (a b c (4))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1253 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1254 @group
5359
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1255 (remove* 'c sample-list)
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1256 @result{} (a b (4))
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1257 @end group
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1258 @group
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1259 sample-list
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1260 @result{} (a b c (4))
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1261 @end group
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1262 @end example
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1263
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1264 Don't assume that a variable which formerly held the argument @var{list}
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1265 now has fewer elements, or that it still holds the original list!
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1266 Instead, save the result of @code{remove*} and use that. Most often we
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1267 store the result back into the variable that held the original list:
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1268
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1269 @example
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1270 (setq flowers (remove* 'rose flowers))
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1271 @end example
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1272
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1273 In the following example, the @code{(4)} that @code{remove*} attempts to match
5361
62b9ef1ed4ac Change "special form" to "special operator" in the manuals, too
Aidan Kehoe <kehoea@parhasard.net>
parents: 5359
diff changeset
1274 and the @code{(4)} in the @code{sample-list} are not @code{eql}:
5359
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1275
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1276 @example
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1277 @group
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1278 (remove* '(4) sample-list)
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1279 @result{} (a b c (4))
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1280 @end group
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1281 @end example
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1282 @end defun
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1283
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1284 @defun remq item sequence
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1285 This is equivalent to calling @code{(remove* item sequence :test #'eq)}.
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1286 @end defun
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1287
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1288 @defun remove item sequence
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1289 This is equivalent to calling @code{(remove* item sequence :test #'equal)}.
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1290 @end defun
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1291
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1292 @defun delete* item sequence @t{&key (test #'eql) (key #'identity) (start 0) (end (length sequence)) from-end count test-not}
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1293 This is like @code{remove*}, but a list @var{sequence} is modified
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1294 in-place (`destructively', in Lisp parlance). So some of the examples
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1295 above change:
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1296
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1297 @example
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1298 @group
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1299 (setq sample-list '(a b c (4)))
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1300 @result{} (a b c (4))
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1301 @end group
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1302 @group
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1303 (delete* 'c sample-list)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1304 @result{} (a b (4))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1305 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1306 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1307 sample-list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1308 @result{} (a b (4))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1309 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1310 @end example
5359
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1311 @end defun
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1312
5359
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1313 @defun delq item sequence
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1314 This is equivalent to calling @code{(delete* item sequence :test #'eq)}.
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1315 @end defun
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1316
5359
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1317 @defun delete item list
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1318 This is equivalent to calling @code{(delete* item sequence :test #'equal)}.
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1319 @end defun
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1320
5359
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1321 @defun subsetp list1 list2 @t{&key :test :test-not :key}
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1322 This function returns non-@code{nil} if every item in @var{list1} is
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1323 present in @var{list2}.
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1324 @end defun
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1325
5359
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1326 @defun union list1 list2 @t{&key :test :test-not :key :stable}
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1327 This function calculates the union of two lists, returning a list
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1328 containing all those items that appear in either list. It doesn't
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1329 guarantee that duplicates in @var{list1} or @var{list2} will be
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1330 eliminated; see @code{remove-duplicates} if this is important to you.
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1331
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1332 A non-nil value for the @code{:stable} keyword, not specified by Common
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1333 Lisp, means return the items in the order they appear in @var{list1},
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1334 followed by the remaining items in the order they appear in @var{list2}.
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1335 The other keywords are as in @code{member*}.
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1336
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1337 @code{union} does not modify @var{list1} or @var{list2}.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1338 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1339
5359
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1340 @defun intersection list1 list2 @t{&key :test :test-not :key :stable}
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1341 This function calculates the intersection of two lists, returning a list
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1342 containing all those items that appear in both lists. It doesn't
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1343 guarantee that duplicates in @var{list1} or @var{list2} will be
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1344 eliminated; see @code{remove-duplicates} if this is important to
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1345 you. @code{intersection} does not modify either list.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1346
5359
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1347 A non-nil value for the @code{:stable} keyword, not specified by Common
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1348 Lisp, means return the items in the order they appear in @var{list1}.
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1349 The other keywords are as in @code{member*}.
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1350 @end defun
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1351
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1352 @defun set-difference list1 list2 @t{&key :test :test-not :key :stable}
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1353 This function returns those items that are in @var{list1} but not in
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1354 @var{list2}. It does not modify either list.
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1355
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1356 A non-nil value for the @code{:stable} keyword, not specified by Common
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1357 Lisp, means return the items in the order they appear in @var{list1}.
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1358 The other keywords are as in @code{member*}.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1359 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1360
5359
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1361 @defun set-exclusive-or list1 list2 @t{&key :test :test-not :key :stable}
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1362 This function returns those items that are in @var{list1} but not in
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1363 @var{list2}, together with those in @var{list2} but not in @var{list1}.
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1364 It does not modify either list.
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1365
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1366 A non-nil value for the @code{:stable} keyword, not specified by Common
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1367 Lisp, means return the items in the order they appear in @var{list1},
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1368 followed by the remaining items in the order they appear in @var{list2}.
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1369 The other keywords are as in @code{member*}.
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1370 @end defun
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1371
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1372 The following functions are equivalent to the previous four functions,
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1373 but with two important differences; they do not accept the
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1374 @code{:stable} keyword, and they modify one or both list arguments in
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1375 the same way @code{delete*} does.
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1376
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1377 @defun nintersection list1 list2 @t{&key :test :test-not :key}
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1378 @end defun
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1379 @defun nset-difference list1 list2 @t{&key :test :test-not :key}
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1380 @end defun
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1381 @defun nset-exclusive-or list1 list2 @t{&key :test :test-not :key}
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1382 @end defun
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1383 @defun nunion list1 list2 @t{&key :test :test-not :key}
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1384 @end defun
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1385
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1386 See also the function @code{add-to-list}, in @ref{Setting Variables},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1387 for another way to add an element to a list stored in a variable.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1388
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1389 @node Association Lists
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1390 @section Association Lists
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1391 @cindex association list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1392 @cindex alist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1393
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1394 An @dfn{association list}, or @dfn{alist} for short, records a mapping
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1395 from keys to values. It is a list of cons cells called
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1396 @dfn{associations}: the @sc{car} of each cell is the @dfn{key}, and the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1397 @sc{cdr} is the @dfn{associated value}.@footnote{This usage of ``key''
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1398 is not related to the term ``key sequence''; it means a value used to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1399 look up an item in a table. In this case, the table is the alist, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1400 the alist associations are the items.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1401
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1402 Here is an example of an alist. The key @code{pine} is associated with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1403 the value @code{cones}; the key @code{oak} is associated with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1404 @code{acorns}; and the key @code{maple} is associated with @code{seeds}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1405
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1406 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1407 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1408 '((pine . cones)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1409 (oak . acorns)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1410 (maple . seeds))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1411 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1412 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1413
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1414 The associated values in an alist may be any Lisp objects; so may the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1415 keys. For example, in the following alist, the symbol @code{a} is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1416 associated with the number @code{1}, and the string @code{"b"} is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1417 associated with the @emph{list} @code{(2 3)}, which is the @sc{cdr} of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1418 the alist element:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1419
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1420 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1421 ((a . 1) ("b" 2 3))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1422 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1423
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1424 Sometimes it is better to design an alist to store the associated
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1425 value in the @sc{car} of the @sc{cdr} of the element. Here is an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1426 example:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1427
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1428 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1429 '((rose red) (lily white) (buttercup yellow))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1430 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1431
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1432 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1433 Here we regard @code{red} as the value associated with @code{rose}. One
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1434 advantage of this method is that you can store other related
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1435 information---even a list of other items---in the @sc{cdr} of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1436 @sc{cdr}. One disadvantage is that you cannot use @code{rassq} (see
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1437 below) to find the element containing a given value. When neither of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1438 these considerations is important, the choice is a matter of taste, as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1439 long as you are consistent about it for any given alist.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1440
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1441 Note that the same alist shown above could be regarded as having the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1442 associated value in the @sc{cdr} of the element; the value associated
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1443 with @code{rose} would be the list @code{(red)}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1444
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1445 Association lists are often used to record information that you might
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1446 otherwise keep on a stack, since new associations may be added easily to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1447 the front of the list. When searching an association list for an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1448 association with a given key, the first one found is returned, if there
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1449 is more than one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1450
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1451 In XEmacs Lisp, it is @emph{not} an error if an element of an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1452 association list is not a cons cell. The alist search functions simply
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1453 ignore such elements. Many other versions of Lisp signal errors in such
5583
10f179710250 Deprecate #'remassoc, #'remassq, #'remrassoc, #'remrassq.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5361
diff changeset
1454 cases, and it is good practice to avoid adding non-cons-cells to association
10f179710250 Deprecate #'remassoc, #'remassq, #'remrassoc, #'remrassq.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5361
diff changeset
1455 lists.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1456
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1457 Note that property lists are similar to association lists in several
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1458 respects. A property list behaves like an association list in which
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1459 each key can occur only once. @xref{Property Lists}, for a comparison
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1460 of property lists and association lists.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1461
5359
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1462 @defun assoc* key alist @t{&key :test :test-not :key}
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1463 This function returns the first association for @var{key} in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1464 @var{alist}. It compares @var{key} against the alist elements using
5359
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1465 @code{eql} (@pxref{Equality Predicates}), or the test specified with the
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1466 @code{:test} keyword. It returns @code{nil} if no association in
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1467 @var{alist} has a @sc{car} @code{equal} to @var{key}. For example:
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1468
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1469 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1470 (setq trees '((pine . cones) (oak . acorns) (maple . seeds)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1471 @result{} ((pine . cones) (oak . acorns) (maple . seeds))
5359
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1472 (assoc* 'oak trees)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1473 @result{} (oak . acorns)
5359
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1474 (cdr (assoc* 'oak trees))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1475 @result{} acorns
5359
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1476 (assoc* 'birch trees)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1477 @result{} nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1478 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1479
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1480 Here is another example, in which the keys and values are not symbols:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1481
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1482 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1483 (setq needles-per-cluster
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1484 '((2 "Austrian Pine" "Red Pine")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1485 (3 "Pitch Pine")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1486 (5 "White Pine")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1487
5359
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1488 (cdr (assoc* 3 needles-per-cluster))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1489 @result{} ("Pitch Pine")
5359
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1490 (cdr (assoc* 2 needles-per-cluster))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1491 @result{} ("Austrian Pine" "Red Pine")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1492 @end smallexample
5359
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1493
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1494 The @code{:test} keyword argument allows you to specify the test used to
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1495 decide whether @var{key} is equivalent to a given element of
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1496 @var{alist}. The function should return non-@code{nil} if the items
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1497 match, @code{nil} if they do not. The @code{:test-not} keyword is
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1498 similar, but the meaning of @code{nil} and non-@code{nil} results are
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1499 reversed. The @code{:key} keyword allows you to examine a component of
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1500 each @sc{car} in @var{alist}, rather than the @sc{car} itself.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1501 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1502
5359
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1503 @defun rassoc* value alist @t{&key :test :test-not :key}
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1504 This function returns the first association with value @var{value} in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1505 @var{alist}. It returns @code{nil} if no association in @var{alist} has
5359
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1506 a @sc{cdr} @code{eql} to @var{value}.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1507
5359
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1508 @code{rassoc*} is like @code{assoc*} except that it compares the @sc{cdr} of
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1509 each @var{alist} association instead of the @sc{car}. You can think of
5359
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1510 this as ``reverse @code{assoc*}'', finding the key for a given value.
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1511
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1512 The keywords work similarly to @code{assoc*}.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1513 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1514
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1515 @defun assq key alist
5359
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1516 This is equivalent to calling @code{(assoc* key alist :test 'eq)}, and
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1517 compiles to the same byte code.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1518
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1519 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1520 (setq trees '((pine . cones) (oak . acorns) (maple . seeds)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1521 @result{} ((pine . cones) (oak . acorns) (maple . seeds))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1522 (assq 'pine trees)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1523 @result{} (pine . cones)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1524 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1525
5359
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1526 @code{assq} is not usually useful in alists where the keys may not be
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1527 symbols:
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1528
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1529 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1530 (setq leaves
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1531 '(("simple leaves" . oak)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1532 ("compound leaves" . horsechestnut)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1533
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1534 (assq "simple leaves" leaves)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1535 @result{} nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1536 (assoc "simple leaves" leaves)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1537 @result{} ("simple leaves" . oak)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1538 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1539 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1540
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1541 @defun rassq value alist
5359
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1542 This is equivalent to calling @code{(rassoc* value alist :test 'eq)}, and
f5a5501814f5 Document the CL set functions and #'eql in the Lispref, not just cl.texi
Aidan Kehoe <kehoea@parhasard.net>
parents: 5300
diff changeset
1543 compiles to the same byte code. For example:
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1544
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1545 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1546 (setq trees '((pine . cones) (oak . acorns) (maple . seeds)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1547
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1548 (rassq 'acorns trees)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1549 @result{} (oak . acorns)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1550 (rassq 'spores trees)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1551 @result{} nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1552 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1553
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1554 Note that @code{rassq} cannot search for a value stored in the @sc{car}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1555 of the @sc{cdr} of an element:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1556
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1557 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1558 (setq colors '((rose red) (lily white) (buttercup yellow)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1559
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1560 (rassq 'white colors)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1561 @result{} nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1562 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1563
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1564 In this case, the @sc{cdr} of the association @code{(lily white)} is not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1565 the symbol @code{white}, but rather the list @code{(white)}. This
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1566 becomes clearer if the association is written in dotted pair notation:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1567
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1568 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1569 (lily white) @equiv{} (lily . (white))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1570 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1571 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1572
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1573 @defun copy-alist alist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1574 @cindex copying alists
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1575 This function returns a two-level deep copy of @var{alist}: it creates a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1576 new copy of each association, so that you can alter the associations of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1577 the new alist without changing the old one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1578
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1579 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1580 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1581 (setq needles-per-cluster
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1582 '((2 . ("Austrian Pine" "Red Pine"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1583 (3 . ("Pitch Pine"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1584 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1585 (5 . ("White Pine"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1586 @result{}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1587 ((2 "Austrian Pine" "Red Pine")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1588 (3 "Pitch Pine")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1589 (5 "White Pine"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1590
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1591 (setq copy (copy-alist needles-per-cluster))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1592 @result{}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1593 ((2 "Austrian Pine" "Red Pine")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1594 (3 "Pitch Pine")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1595 (5 "White Pine"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1596
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1597 (eq needles-per-cluster copy)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1598 @result{} nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1599 (equal needles-per-cluster copy)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1600 @result{} t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1601 (eq (car needles-per-cluster) (car copy))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1602 @result{} nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1603 (cdr (car (cdr needles-per-cluster)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1604 @result{} ("Pitch Pine")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1605 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1606 (eq (cdr (car (cdr needles-per-cluster)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1607 (cdr (car (cdr copy))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1608 @result{} t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1609 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1610 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1611
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1612 This example shows how @code{copy-alist} makes it possible to change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1613 the associations of one copy without affecting the other:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1614
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1615 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1616 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1617 (setcdr (assq 3 copy) '("Martian Vacuum Pine"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1618 (cdr (assq 3 needles-per-cluster))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1619 @result{} ("Pitch Pine")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1620 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1621 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1622 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1623
5583
10f179710250 Deprecate #'remassoc, #'remassq, #'remrassoc, #'remrassq.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5361
diff changeset
1624 For removing elements from alists, use @code{remove*} or @code{delete*} with
10f179710250 Deprecate #'remassoc, #'remassq, #'remrassoc, #'remrassq.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5361
diff changeset
1625 appropriate @code{:key} arguments. If it is necessary that XEmacs not error
10f179710250 Deprecate #'remassoc, #'remassq, #'remrassoc, #'remrassq.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5361
diff changeset
1626 on encountering a non-cons in such a list, there are XEmacs-specific functions
10f179710250 Deprecate #'remassoc, #'remassq, #'remrassoc, #'remrassq.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5361
diff changeset
1627 @code{remassq}, @code{remrassq}, @code{remassoc}, and @code{remrassoc} with
10f179710250 Deprecate #'remassoc, #'remassq, #'remrassoc, #'remrassq.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5361
diff changeset
1628 this behavior, but they are neither available under GNU Emacs nor Common Lisp.
10f179710250 Deprecate #'remassoc, #'remassq, #'remrassoc, #'remrassq.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5361
diff changeset
1629 They are marked as obsolete, and it is preferable to fix your code to avoid
10f179710250 Deprecate #'remassoc, #'remassq, #'remrassoc, #'remrassq.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5361
diff changeset
1630 adding non-cons objects to alists.
10f179710250 Deprecate #'remassoc, #'remassq, #'remrassoc, #'remrassq.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5361
diff changeset
1631
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1632 @node Property Lists
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1633 @section Property Lists
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1634 @cindex property list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1635 @cindex plist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1636
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1637 A @dfn{property list} (or @dfn{plist}) is another way of representing a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1638 mapping from keys to values. Instead of the list consisting of conses
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1639 of a key and a value, the keys and values alternate as successive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1640 entries in the list. Thus, the association list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1641
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1642 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1643 ((a . 1) (b . 2) (c . 3))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1644 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1645
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1646 has the equivalent property list form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1647
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1648 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1649 (a 1 b 2 c 3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1650 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1651
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1652 Property lists are used to represent the properties associated with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1653 various sorts of objects, such as symbols, strings, frames, etc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1654 The convention is that property lists can be modified in-place,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1655 while association lists generally are not.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1656
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1657 Plists come in two varieties: @dfn{normal} plists, whose keys are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1658 compared with @code{eq}, and @dfn{lax} plists, whose keys are compared
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1659 with @code{equal},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1660
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1661 @defun valid-plist-p plist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1662 Given a plist, this function returns non-@code{nil} if its format is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1663 correct. If it returns @code{nil}, @code{check-valid-plist} will signal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1664 an error when given the plist; that means it's a malformed or circular
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1665 plist or has non-symbols as keywords.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1666 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1667
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1668 @defun check-valid-plist plist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1669 Given a plist, this function signals an error if there is anything wrong
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1670 with it. This means that it's a malformed or circular plist.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1671 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1672
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1673 @menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1674 * Working With Normal Plists:: Functions for normal plists.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1675 * Working With Lax Plists:: Functions for lax plists.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1676 * Converting Plists To/From Alists:: Alist to plist and vice-versa.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1677 @end menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1678
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1679 @node Working With Normal Plists
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1680 @subsection Working With Normal Plists
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1681
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
1682 @defun plist-get plist property &optional default
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1683 This function extracts a value from a property list. The function
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
1684 returns the value corresponding to the given @var{property}, or
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
1685 @var{default} if @var{property} is not one of the properties on the list.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1686 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1687
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
1688 @defun plist-put plist property value
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
1689 This function changes the value in @var{plist} of @var{property} to
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
1690 @var{value}. If @var{property} is already a property on the list, its value is
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
1691 set to @var{value}, otherwise the new @var{property} @var{value} pair is added.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
1692 The new plist is returned; use @code{(setq x (plist-put x property value))} to
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1693 be sure to use the new value. The @var{plist} is modified by side
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1694 effects.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1695 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1696
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
1697 @defun plist-remprop plist property
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
1698 This function removes from @var{plist} the property @var{property} and its
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1699 value. The new plist is returned; use @code{(setq x (plist-remprop x
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
1700 property))} to be sure to use the new value. The @var{plist} is
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1701 modified by side effects.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1702 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1703
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
1704 @defun plist-member plist property
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
1705 This function returns @code{t} if @var{property} has a value specified in
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1706 @var{plist}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1707 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1708
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1709 In the following functions, if optional arg @var{nil-means-not-present}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1710 is non-@code{nil}, then a property with a @code{nil} value is ignored or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1711 removed. This feature is a virus that has infected old Lisp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1712 implementations (and thus E-Lisp, due to @sc{rms}'s enamorment with old
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1713 Lisps), but should not be used except for backward compatibility.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1714
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1715 @defun plists-eq a b &optional nil-means-not-present
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1716 This function returns non-@code{nil} if property lists A and B are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1717 @code{eq} (i.e. their values are @code{eq}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1718 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1719
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1720 @defun plists-equal a b &optional nil-means-not-present
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1721 This function returns non-@code{nil} if property lists A and B are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1722 @code{equal} (i.e. their values are @code{equal}; their keys are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1723 still compared using @code{eq}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1724 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1725
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1726 @defun canonicalize-plist plist &optional nil-means-not-present
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1727 This function destructively removes any duplicate entries from a plist.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1728 In such cases, the first entry applies.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1729
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1730 The new plist is returned. If @var{nil-means-not-present} is given, the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1731 return value may not be @code{eq} to the passed-in value, so make sure
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1732 to @code{setq} the value back into where it came from.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1733 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1734
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1735 @node Working With Lax Plists
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1736 @subsection Working With Lax Plists
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1737
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1738 Recall that a @dfn{lax plist} is a property list whose keys are compared
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1739 using @code{equal} instead of @code{eq}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1740
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
1741 @defun lax-plist-get lax-plist property &optional default
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1742 This function extracts a value from a lax property list. The function
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
1743 returns the value corresponding to the given @var{property}, or
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
1744 @var{default} if @var{property} is not one of the properties on the list.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1745 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1746
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
1747 @defun lax-plist-put lax-plist property value
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
1748 This function changes the value in @var{lax-plist} of @var{property} to @var{value}.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1749 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1750
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
1751 @defun lax-plist-remprop lax-plist property
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
1752 This function removes from @var{lax-plist} the property @var{property} and
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1753 its value. The new plist is returned; use @code{(setq x
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
1754 (lax-plist-remprop x property))} to be sure to use the new value. The
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1755 @var{lax-plist} is modified by side effects.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1756 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1757
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
1758 @defun lax-plist-member lax-plist property
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
1759 This function returns @code{t} if @var{property} has a value specified in
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1760 @var{lax-plist}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1761 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1762
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1763 In the following functions, if optional arg @var{nil-means-not-present}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1764 is non-@code{nil}, then a property with a @code{nil} value is ignored or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1765 removed. This feature is a virus that has infected old Lisp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1766 implementations (and thus E-Lisp, due to @sc{rms}'s enamorment with old
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1767 Lisps), but should not be used except for backward compatibility.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1768
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1769 @defun lax-plists-eq a b &optional nil-means-not-present
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1770 This function returns non-@code{nil} if lax property lists A and B are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1771 @code{eq} (i.e. their values are @code{eq}; their keys are still
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1772 compared using @code{equal}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1773 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1774
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1775 @defun lax-plists-equal a b &optional nil-means-not-present
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1776 This function returns non-@code{nil} if lax property lists A and B are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1777 @code{equal} (i.e. their values are @code{equal}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1778 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1779
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1780 @defun canonicalize-lax-plist lax-plist &optional nil-means-not-present
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1781 This function destructively removes any duplicate entries from a lax
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1782 plist. In such cases, the first entry applies.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1783
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1784 The new plist is returned. If @var{nil-means-not-present} is given, the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1785 return value may not be @code{eq} to the passed-in value, so make sure
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1786 to @code{setq} the value back into where it came from.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1787 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1788
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1789 @node Converting Plists To/From Alists
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1790 @subsection Converting Plists To/From Alists
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1791
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1792 @defun alist-to-plist alist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1793 This function converts association list @var{alist} into the equivalent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1794 property-list form. The plist is returned. This converts from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1795
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1796 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1797 ((a . 1) (b . 2) (c . 3))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1798 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1799
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1800 into
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1801
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1802 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1803 (a 1 b 2 c 3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1804 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1805
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1806 The original alist is not modified.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1807 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1808
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1809 @defun plist-to-alist plist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1810 This function converts property list @var{plist} into the equivalent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1811 association-list form. The alist is returned. This converts from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1812
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1813 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1814 (a 1 b 2 c 3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1815 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1816
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1817 into
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1818
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1819 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1820 ((a . 1) (b . 2) (c . 3))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1821 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1822
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1823 The original plist is not modified.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1824 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1825
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1826 The following two functions are equivalent to the preceding two except
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1827 that they destructively modify their arguments, using cons cells from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1828 the original list to form the new list rather than allocating new
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1829 cons cells.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1830
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1831 @defun destructive-alist-to-plist alist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1832 This function destructively converts association list @var{alist} into
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1833 the equivalent property-list form. The plist is returned.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1834 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1835
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1836 @defun destructive-plist-to-alist plist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1837 This function destructively converts property list @var{plist} into the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1838 equivalent association-list form. The alist is returned.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1839 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1840
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1841 @node Weak Lists
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1842 @section Weak Lists
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1843 @cindex weak list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1844
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1845 A @dfn{weak list} is a special sort of list whose members are not counted
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1846 as references for the purpose of garbage collection. This means that,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1847 for any object in the list, if there are no references to the object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1848 anywhere outside of the list (or other weak list or weak hash table),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1849 that object will disappear the next time a garbage collection happens.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1850 Weak lists can be useful for keeping track of things such as unobtrusive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1851 lists of another function's buffers or markers. When that function is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1852 done with the elements, they will automatically disappear from the list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1853
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1854 Weak lists are used internally, for example, to manage the list holding
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
1855 the children of an extent---an extent that is unused but has a parent
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1856 will still be reclaimed, and will automatically be removed from its
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1857 parent's list of children.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1858
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1859 Weak lists are similar to weak hash tables (@pxref{Weak Hash Tables}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1860
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1861 @defun weak-list-p object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1862 This function returns non-@code{nil} if @var{object} is a weak list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1863 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1864
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1865 Weak lists come in one of four types:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1866
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1867 @table @code
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1868 @item simple
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1869 Objects in the list disappear if not referenced outside of the list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1870
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1871 @item assoc
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1872 Objects in the list disappear if they are conses and either the car or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1873 the cdr of the cons is not referenced outside of the list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1874
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1875 @item key-assoc
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1876 Objects in the list disappear if they are conses and the car is not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1877 referenced outside of the list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1878
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1879 @item value-assoc
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1880 Objects in the list disappear if they are conses and the cdr is not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1881 referenced outside of the list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1882 @end table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1883
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1884 @defun make-weak-list &optional type
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1885 This function creates a new weak list of type @var{type}. @var{type} is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1886 a symbol (one of @code{simple}, @code{assoc}, @code{key-assoc}, or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1887 @code{value-assoc}, as described above) and defaults to @code{simple}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1888 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1889
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1890 @defun weak-list-type weak
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1891 This function returns the type of the given weak-list object.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1892 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1893
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1894 @defun weak-list-list weak
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1895 This function returns the list contained in a weak-list object.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1896 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1897
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1898 @defun set-weak-list-list weak new-list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1899 This function changes the list contained in a weak-list object.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1900 @end defun