aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2012-01-23 12:23:50 +0800
committerChong Yidong2012-01-23 12:23:50 +0800
commit31cbea1d3d3c548025f70551514bd1a370301ccf (patch)
tree5643d70c29d6489feec93b45b135ee25bd7ae8a1
parent2724d9c71e29aa0aa298c3534b0b7b18d8fc6202 (diff)
downloademacs-31cbea1d3d3c548025f70551514bd1a370301ccf.tar.gz
emacs-31cbea1d3d3c548025f70551514bd1a370301ccf.zip
Update several Lisp manual chapters.
* doc/lispref/eval.texi (Intro Eval, Symbol Forms): Minor tweaks for correctness with lexical scoping. (Eval): Copyedits. * doc/lispref/sequences.texi (Sequence Functions): Don't repeat the introduction already given in the parent. (Vectors): Copyedits. (Rings): Move from lists.texi. Note that this is specific to the ring package. * doc/lispref/lists.texi (Cons Cells): Copyedits. (List Elements): Mention push. (List Variables): Mention pop. (Rings): Move to sequences.texi. * doc/lispref/strings.texi (Text Comparison): Minor qualification. * doc/lispref/symbols.texi (Definitions, Symbol Components): Mention variable scoping issues. (Plists and Alists): Copyedits.
-rw-r--r--admin/FOR-RELEASE19
-rw-r--r--doc/lispref/ChangeLog23
-rw-r--r--doc/lispref/control.texi10
-rw-r--r--doc/lispref/elisp.texi2
-rw-r--r--doc/lispref/eval.texi24
-rw-r--r--doc/lispref/lists.texi163
-rw-r--r--doc/lispref/sequences.texi120
-rw-r--r--doc/lispref/strings.texi13
-rw-r--r--doc/lispref/symbols.texi176
9 files changed, 281 insertions, 269 deletions
diff --git a/admin/FOR-RELEASE b/admin/FOR-RELEASE
index 9335e5b1fbe..f704a3c9397 100644
--- a/admin/FOR-RELEASE
+++ b/admin/FOR-RELEASE
@@ -187,25 +187,25 @@ backups.texi
187buffers.texi 187buffers.texi
188commands.texi 188commands.texi
189compile.texi 189compile.texi
190control.texi 190control.texi cyd
191customize.texi 191customize.texi
192debugging.texi 192debugging.texi
193display.texi 193display.texi
194edebug.texi 194edebug.texi
195elisp.texi 195elisp.texi
196errors.texi 196errors.texi
197eval.texi 197eval.texi cyd
198files.texi 198files.texi
199frames.texi 199frames.texi
200functions.texi 200functions.texi
201hash.texi 201hash.texi cyd
202help.texi 202help.texi
203hooks.texi 203hooks.texi
204index.texi 204index.texi
205internals.texi 205internals.texi
206intro.texi cyd 206intro.texi cyd
207keymaps.texi 207keymaps.texi
208lists.texi 208lists.texi cyd
209loading.texi 209loading.texi
210locals.texi 210locals.texi
211macros.texi 211macros.texi
@@ -214,17 +214,17 @@ markers.texi
214minibuf.texi 214minibuf.texi
215modes.texi 215modes.texi
216nonascii.texi 216nonascii.texi
217numbers.texi 217numbers.texi cyd
218objects.texi cyd 218objects.texi cyd
219os.texi 219os.texi
220package.texi 220package.texi
221positions.texi 221positions.texi
222processes.texi 222processes.texi
223searching.texi 223searching.texi
224sequences.texi 224sequences.texi cyd
225streams.texi 225streams.texi
226strings.texi 226strings.texi cyd
227symbols.texi 227symbols.texi cyd
228syntax.texi 228syntax.texi
229text.texi 229text.texi
230tips.texi 230tips.texi
@@ -232,8 +232,7 @@ variables.texi
232windows.texi 232windows.texi
233 233
234* PLANNED ADDITIONS 234* PLANNED ADDITIONS
235 235* pov-mode (probably not for Emacs-23: waiting for a Free POV-Ray).
236** pov-mode (probably not for Emacs-23: waiting for a Free POV-Ray).
237** gas-mode ? 236** gas-mode ?
238 237
239 238
diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog
index 3c18de96d72..b66f82c5738 100644
--- a/doc/lispref/ChangeLog
+++ b/doc/lispref/ChangeLog
@@ -1,3 +1,26 @@
12012-01-23 Chong Yidong <cyd@gnu.org>
2
3 * strings.texi (Text Comparison): Minor qualification.
4
5 * lists.texi (Cons Cells): Copyedits.
6 (List Elements): Mention push.
7 (List Variables): Mention pop.
8 (Rings): Move to sequences.texi.
9
10 * sequences.texi (Sequence Functions): Don't repeat the
11 introduction already given in the parent.
12 (Vectors): Copyedits.
13 (Rings): Move from lists.texi. Note that this is specific to the
14 ring package.
15
16 * symbols.texi (Definitions, Symbol Components): Mention variable
17 scoping issues.
18 (Plists and Alists): Copyedits.
19
20 * eval.texi (Intro Eval, Symbol Forms): Minor tweaks for
21 correctness with lexical scoping.
22 (Eval): Copyedits.
23
12012-01-21 Chong Yidong <cyd@gnu.org> 242012-01-21 Chong Yidong <cyd@gnu.org>
2 25
3 * intro.texi (A Sample Function Description): Special notation 26 * intro.texi (A Sample Function Description): Special notation
diff --git a/doc/lispref/control.texi b/doc/lispref/control.texi
index e74f3e198bf..0511f21007d 100644
--- a/doc/lispref/control.texi
+++ b/doc/lispref/control.texi
@@ -8,11 +8,11 @@
8@cindex special forms for control structures 8@cindex special forms for control structures
9@cindex control structures 9@cindex control structures
10 10
11 A Lisp program consists of expressions or @dfn{forms} (@pxref{Forms}). 11 A Lisp program consists of a set of @dfn{expressions}, or
12We control the order of execution of these forms by enclosing them in 12@dfn{forms} (@pxref{Forms}). We control the order of execution of
13@dfn{control structures}. Control structures are special forms which 13these forms by enclosing them in @dfn{control structures}. Control
14control when, whether, or how many times to execute the forms they 14structures are special forms which control when, whether, or how many
15contain. 15times to execute the forms they contain.
16 16
17@cindex textual order 17@cindex textual order
18 The simplest order of execution is sequential execution: first form 18 The simplest order of execution is sequential execution: first form
diff --git a/doc/lispref/elisp.texi b/doc/lispref/elisp.texi
index 0b8d972c1d5..1555b98e7fb 100644
--- a/doc/lispref/elisp.texi
+++ b/doc/lispref/elisp.texi
@@ -326,7 +326,6 @@ Lists
326* Modifying Lists:: Storing new pieces into an existing list. 326* Modifying Lists:: Storing new pieces into an existing list.
327* Sets And Lists:: A list can represent a finite mathematical set. 327* Sets And Lists:: A list can represent a finite mathematical set.
328* Association Lists:: A list can represent a finite relation or mapping. 328* Association Lists:: A list can represent a finite relation or mapping.
329* Rings:: Managing a fixed-size ring of objects.
330 329
331Modifying Existing List Structure 330Modifying Existing List Structure
332 331
@@ -344,6 +343,7 @@ Sequences, Arrays, and Vectors
344* Vector Functions:: Functions specifically for vectors. 343* Vector Functions:: Functions specifically for vectors.
345* Char-Tables:: How to work with char-tables. 344* Char-Tables:: How to work with char-tables.
346* Bool-Vectors:: How to work with bool-vectors. 345* Bool-Vectors:: How to work with bool-vectors.
346* Rings:: Managing a fixed-size ring of objects.
347 347
348Hash Tables 348Hash Tables
349 349
diff --git a/doc/lispref/eval.texi b/doc/lispref/eval.texi
index adb4841a82d..fc18e503543 100644
--- a/doc/lispref/eval.texi
+++ b/doc/lispref/eval.texi
@@ -64,8 +64,8 @@ evaluate a @dfn{function call} form such as @code{(car x)}, Emacs
64first evaluates the argument (the subform @code{x}). After evaluating 64first evaluates the argument (the subform @code{x}). After evaluating
65the argument, Emacs @dfn{executes} the function (@code{car}), and if 65the argument, Emacs @dfn{executes} the function (@code{car}), and if
66the function is written in Lisp, execution works by evaluating the 66the function is written in Lisp, execution works by evaluating the
67@dfn{body} of the function. (In this example, however, @code{car} is 67@dfn{body} of the function (in this example, however, @code{car} is
68not a Lisp function; it is a primitive function implemented in C.) 68not a Lisp function; it is a primitive function implemented in C).
69@xref{Functions}, for more information about functions and function 69@xref{Functions}, for more information about functions and function
70calls. 70calls.
71 71
@@ -77,9 +77,8 @@ variables (@pxref{Variables}).@footnote{This definition of
77that can affect the result of a program.} Whenever a form refers to a 77that can affect the result of a program.} Whenever a form refers to a
78variable without creating a new binding for it, the variable evaluates 78variable without creating a new binding for it, the variable evaluates
79to the value given by the current environment. Evaluating a form may 79to the value given by the current environment. Evaluating a form may
80create a new environment for recursive evaluation, by binding 80also temporarily alter the environment by binding variables
81variables (@pxref{Local Variables}). Such environments are temporary, 81(@pxref{Local Variables}).
82and vanish when the evaluation of the form is complete.
83 82
84@cindex side effect 83@cindex side effect
85 Evaluating a form may also make changes that persist; these changes 84 Evaluating a form may also make changes that persist; these changes
@@ -177,9 +176,9 @@ program. Here is an example:
177@cindex symbol evaluation 176@cindex symbol evaluation
178 177
179 When a symbol is evaluated, it is treated as a variable. The result 178 When a symbol is evaluated, it is treated as a variable. The result
180is the variable's value, if it has one. If it has none (if its value 179is the variable's value, if it has one. If the symbol has no value as
181cell is void), an error is signaled. For more information on the use of 180a variable, the Lisp interpreter signals an error. For more
182variables, see @ref{Variables}. 181information on the use of variables, see @ref{Variables}.
183 182
184 In the following example, we set the value of a symbol with 183 In the following example, we set the value of a symbol with
185@code{setq}. Then we evaluate the symbol, and get back the value that 184@code{setq}. Then we evaluate the symbol, and get back the value that
@@ -602,12 +601,13 @@ functions provides the ability to pass information to them as
602arguments. 601arguments.
603 602
604@defun eval form &optional lexical 603@defun eval form &optional lexical
605This is the basic function evaluating an expression. It evaluates 604This is the basic function for evaluating an expression. It evaluates
606@var{form} in the current environment and returns the result. How the 605@var{form} in the current environment and returns the result. How the
607evaluation proceeds depends on the type of the object (@pxref{Forms}). 606evaluation proceeds depends on the type of the object (@pxref{Forms}).
608@var{lexical} if non-nil means to evaluate @var{form} using lexical scoping 607
609rules (@pxref{Lexical Binding}) instead of the default dynamic scoping used 608The argument @var{lexical}, if non-@code{nil}, means to evaluate
610historically in Emacs Lisp. 609@var{form} using lexical scoping rules for variables, instead of the
610default dynamic scoping rules. @xref{Lexical Binding}.
611 611
612Since @code{eval} is a function, the argument expression that appears 612Since @code{eval} is a function, the argument expression that appears
613in a call to @code{eval} is evaluated twice: once as preparation before 613in a call to @code{eval} is evaluated twice: once as preparation before
diff --git a/doc/lispref/lists.texi b/doc/lispref/lists.texi
index eb9ddf58603..c8433c79b54 100644
--- a/doc/lispref/lists.texi
+++ b/doc/lispref/lists.texi
@@ -23,7 +23,6 @@ the whole list.
23* Modifying Lists:: Storing new pieces into an existing list. 23* Modifying Lists:: Storing new pieces into an existing list.
24* Sets And Lists:: A list can represent a finite mathematical set. 24* Sets And Lists:: A list can represent a finite mathematical set.
25* Association Lists:: A list can represent a finite relation or mapping. 25* Association Lists:: A list can represent a finite relation or mapping.
26* Rings:: Managing a fixed-size ring of objects.
27@end menu 26@end menu
28 27
29@node Cons Cells 28@node Cons Cells
@@ -31,61 +30,56 @@ the whole list.
31@cindex lists and cons cells 30@cindex lists and cons cells
32 31
33 Lists in Lisp are not a primitive data type; they are built up from 32 Lists in Lisp are not a primitive data type; they are built up from
34@dfn{cons cells}. A cons cell is a data object that represents an 33@dfn{cons cells} (@pxref{Cons Cell Type}). A cons cell is a data
35ordered pair. That is, it has two slots, and each slot @dfn{holds}, or 34object that represents an ordered pair. That is, it has two slots,
36@dfn{refers to}, some Lisp object. One slot is known as the @sc{car}, 35and each slot @dfn{holds}, or @dfn{refers to}, some Lisp object. One
37and the other is known as the @sc{cdr}. (These names are traditional; 36slot is known as the @sc{car}, and the other is known as the @sc{cdr}.
38see @ref{Cons Cell Type}.) @sc{cdr} is pronounced ``could-er.'' 37(These names are traditional; see @ref{Cons Cell Type}.) @sc{cdr} is
38pronounced ``could-er.''
39 39
40 We say that ``the @sc{car} of this cons cell is'' whatever object 40 We say that ``the @sc{car} of this cons cell is'' whatever object
41its @sc{car} slot currently holds, and likewise for the @sc{cdr}. 41its @sc{car} slot currently holds, and likewise for the @sc{cdr}.
42 42
43 A list is a series of cons cells ``chained together,'' so that each 43 A list is a series of cons cells ``chained together,'' so that each
44cell refers to the next one. There is one cons cell for each element of 44cell refers to the next one. There is one cons cell for each element
45the list. By convention, the @sc{car}s of the cons cells hold the 45of the list. By convention, the @sc{car}s of the cons cells hold the
46elements of the list, and the @sc{cdr}s are used to chain the list: the 46elements of the list, and the @sc{cdr}s are used to chain the list
47@sc{cdr} slot of each cons cell refers to the following cons cell. The 47(this asymmetry between @sc{car} and @sc{cdr} is entirely a matter of
48@sc{cdr} of the last cons cell is @code{nil}. This asymmetry between 48convention; at the level of cons cells, the @sc{car} and @sc{cdr}
49the @sc{car} and the @sc{cdr} is entirely a matter of convention; at the 49slots have similar properties). Hence, the @sc{cdr} slot of each cons
50level of cons cells, the @sc{car} and @sc{cdr} slots have the same 50cell in a list refers to the following cons cell.
51characteristics.
52 51
53@cindex true list 52@cindex true list
54 Since @code{nil} is the conventional value to put in the @sc{cdr} of 53 Also by convention, the @sc{cdr} of the last cons cell in a list is
55the last cons cell in the list, we call that case a @dfn{true list}. 54@code{nil}. We call such a @code{nil}-terminated structure a
56 55@dfn{true list}. In Emacs Lisp, the symbol @code{nil} is both a
57 In Lisp, we consider the symbol @code{nil} a list as well as a 56symbol and a list with no elements. For convenience, the symbol
58symbol; it is the list with no elements. For convenience, the symbol
59@code{nil} is considered to have @code{nil} as its @sc{cdr} (and also 57@code{nil} is considered to have @code{nil} as its @sc{cdr} (and also
60as its @sc{car}). Therefore, the @sc{cdr} of a true list is always a 58as its @sc{car}).
61true list. 59
60 Hence, the @sc{cdr} of a true list is always a true list. The
61@sc{cdr} of a nonempty true list is a true list containing all the
62elements except the first.
62 63
63@cindex dotted list 64@cindex dotted list
64@cindex circular list 65@cindex circular list
65 If the @sc{cdr} of a list's last cons cell is some other value, 66 If the @sc{cdr} of a list's last cons cell is some value other than
66neither @code{nil} nor another cons cell, we call the structure a 67@code{nil}, we call the structure a @dfn{dotted list}, since its
67@dfn{dotted list}, since its printed representation would use 68printed representation would use dotted pair notation (@pxref{Dotted
68@samp{.}. There is one other possibility: some cons cell's @sc{cdr} 69Pair Notation}). There is one other possibility: some cons cell's
69could point to one of the previous cons cells in the list. We call 70@sc{cdr} could point to one of the previous cons cells in the list.
70that structure a @dfn{circular list}. 71We call that structure a @dfn{circular list}.
71 72
72 For some purposes, it does not matter whether a list is true, 73 For some purposes, it does not matter whether a list is true,
73circular or dotted. If the program doesn't look far enough down the 74circular or dotted. If a program doesn't look far enough down the
74list to see the @sc{cdr} of the final cons cell, it won't care. 75list to see the @sc{cdr} of the final cons cell, it won't care.
75However, some functions that operate on lists demand true lists and 76However, some functions that operate on lists demand true lists and
76signal errors if given a dotted list. Most functions that try to find 77signal errors if given a dotted list. Most functions that try to find
77the end of a list enter infinite loops if given a circular list. 78the end of a list enter infinite loops if given a circular list.
78 79
79@cindex list structure 80@cindex list structure
80 Because most cons cells are used as part of lists, the phrase 81 Because most cons cells are used as part of lists, we refer to any
81@dfn{list structure} has come to mean any structure made out of cons 82structure made out of cons cells as a @dfn{list structure}.
82cells.
83
84 The @sc{cdr} of any nonempty true list @var{l} is a list containing all the
85elements of @var{l} except the first.
86
87 @xref{Cons Cell Type}, for the read and print syntax of cons cells and
88lists, and for ``box and arrow'' illustrations of lists.
89 83
90@node List-related Predicates 84@node List-related Predicates
91@section Predicates on Lists 85@section Predicates on Lists
@@ -257,6 +251,10 @@ x
257x 251x
258 @result{} (b c) 252 @result{} (b c)
259@end example 253@end example
254
255@noindent
256For the @code{pop} macro, which removes an element from a list,
257@xref{List Variables}.
260@end defmac 258@end defmac
261 259
262@defun nth n list 260@defun nth n list
@@ -695,6 +693,10 @@ This macro provides an alternative way to write
695l 693l
696 @result{} (c a b) 694 @result{} (c a b)
697@end example 695@end example
696
697@noindent
698For the @code{pop} macro, which removes the first element from a list,
699@xref{List Elements}.
698@end defmac 700@end defmac
699 701
700 Two functions modify lists that are the values of variables. 702 Two functions modify lists that are the values of variables.
@@ -1800,90 +1802,3 @@ often modifies the original list structure of @var{alist}.
1800compares the @sc{cdr} of each @var{alist} association instead of the 1802compares the @sc{cdr} of each @var{alist} association instead of the
1801@sc{car}. 1803@sc{car}.
1802@end defun 1804@end defun
1803
1804@node Rings
1805@section Managing a Fixed-Size Ring of Objects
1806
1807@cindex ring data structure
1808 This section describes functions for operating on rings. A
1809@dfn{ring} is a fixed-size data structure that supports insertion,
1810deletion, rotation, and modulo-indexed reference and traversal.
1811
1812@defun make-ring size
1813This returns a new ring capable of holding @var{size} objects.
1814@var{size} should be an integer.
1815@end defun
1816
1817@defun ring-p object
1818This returns @code{t} if @var{object} is a ring, @code{nil} otherwise.
1819@end defun
1820
1821@defun ring-size ring
1822This returns the maximum capacity of the @var{ring}.
1823@end defun
1824
1825@defun ring-length ring
1826This returns the number of objects that @var{ring} currently contains.
1827The value will never exceed that returned by @code{ring-size}.
1828@end defun
1829
1830@defun ring-elements ring
1831This returns a list of the objects in @var{ring}, in order, newest first.
1832@end defun
1833
1834@defun ring-copy ring
1835This returns a new ring which is a copy of @var{ring}.
1836The new ring contains the same (@code{eq}) objects as @var{ring}.
1837@end defun
1838
1839@defun ring-empty-p ring
1840This returns @code{t} if @var{ring} is empty, @code{nil} otherwise.
1841@end defun
1842
1843 The newest element in the ring always has index 0. Higher indices
1844correspond to older elements. Indices are computed modulo the ring
1845length. Index @minus{}1 corresponds to the oldest element, @minus{}2
1846to the next-oldest, and so forth.
1847
1848@defun ring-ref ring index
1849This returns the object in @var{ring} found at index @var{index}.
1850@var{index} may be negative or greater than the ring length. If
1851@var{ring} is empty, @code{ring-ref} signals an error.
1852@end defun
1853
1854@defun ring-insert ring object
1855This inserts @var{object} into @var{ring}, making it the newest
1856element, and returns @var{object}.
1857
1858If the ring is full, insertion removes the oldest element to
1859make room for the new element.
1860@end defun
1861
1862@defun ring-remove ring &optional index
1863Remove an object from @var{ring}, and return that object. The
1864argument @var{index} specifies which item to remove; if it is
1865@code{nil}, that means to remove the oldest item. If @var{ring} is
1866empty, @code{ring-remove} signals an error.
1867@end defun
1868
1869@defun ring-insert-at-beginning ring object
1870This inserts @var{object} into @var{ring}, treating it as the oldest
1871element. The return value is not significant.
1872
1873If the ring is full, this function removes the newest element to make
1874room for the inserted element.
1875@end defun
1876
1877@cindex fifo data structure
1878 If you are careful not to exceed the ring size, you can
1879use the ring as a first-in-first-out queue. For example:
1880
1881@lisp
1882(let ((fifo (make-ring 5)))
1883 (mapc (lambda (obj) (ring-insert fifo obj))
1884 '(0 one "two"))
1885 (list (ring-remove fifo) t
1886 (ring-remove fifo) t
1887 (ring-remove fifo)))
1888 @result{} (0 t one t "two")
1889@end lisp
diff --git a/doc/lispref/sequences.texi b/doc/lispref/sequences.texi
index 0ea32f99e12..94f1bf666d2 100644
--- a/doc/lispref/sequences.texi
+++ b/doc/lispref/sequences.texi
@@ -8,10 +8,10 @@
8@chapter Sequences, Arrays, and Vectors 8@chapter Sequences, Arrays, and Vectors
9@cindex sequence 9@cindex sequence
10 10
11 Recall that the @dfn{sequence} type is the union of two other Lisp 11 The @dfn{sequence} type is the union of two other Lisp types: lists
12types: lists and arrays. In other words, any list is a sequence, and 12and arrays. In other words, any list is a sequence, and any array is
13any array is a sequence. The common property that all sequences have is 13a sequence. The common property that all sequences have is that each
14that each is an ordered collection of elements. 14is an ordered collection of elements.
15 15
16 An @dfn{array} is a fixed-length object with a slot for each of its 16 An @dfn{array} is a fixed-length object with a slot for each of its
17elements. All the elements are accessible in constant time. The four 17elements. All the elements are accessible in constant time. The four
@@ -54,19 +54,17 @@ But it is possible to add elements to the list, or remove elements.
54* Vector Functions:: Functions specifically for vectors. 54* Vector Functions:: Functions specifically for vectors.
55* Char-Tables:: How to work with char-tables. 55* Char-Tables:: How to work with char-tables.
56* Bool-Vectors:: How to work with bool-vectors. 56* Bool-Vectors:: How to work with bool-vectors.
57* Rings:: Managing a fixed-size ring of objects.
57@end menu 58@end menu
58 59
59@node Sequence Functions 60@node Sequence Functions
60@section Sequences 61@section Sequences
61 62
62 In Emacs Lisp, a @dfn{sequence} is either a list or an array. The 63 This section describes functions that accept any kind of sequence.
63common property of all sequences is that they are ordered collections of
64elements. This section describes functions that accept any kind of
65sequence.
66 64
67@defun sequencep object 65@defun sequencep object
68Returns @code{t} if @var{object} is a list, vector, string, 66This function returns @code{t} if @var{object} is a list, vector,
69bool-vector, or char-table, @code{nil} otherwise. 67string, bool-vector, or char-table, @code{nil} otherwise.
70@end defun 68@end defun
71 69
72@defun length sequence 70@defun length sequence
@@ -149,8 +147,9 @@ This function generalizes @code{aref} (@pxref{Array Functions}) and
149 147
150@defun copy-sequence sequence 148@defun copy-sequence sequence
151@cindex copying sequences 149@cindex copying sequences
152Returns a copy of @var{sequence}. The copy is the same type of object 150This function returns a copy of @var{sequence}. The copy is the same
153as the original sequence, and it has the same elements in the same order. 151type of object as the original sequence, and it has the same elements
152in the same order.
154 153
155Storing a new element into the copy does not affect the original 154Storing a new element into the copy does not affect the original
156@var{sequence}, and vice versa. However, the elements of the new 155@var{sequence}, and vice versa. However, the elements of the new
@@ -394,8 +393,8 @@ symbol-lookup tables (@pxref{Creating Symbols}), as part of the
394representation of a byte-compiled function (@pxref{Byte Compilation}), 393representation of a byte-compiled function (@pxref{Byte Compilation}),
395and more. 394and more.
396 395
397 In Emacs Lisp, the indices of the elements of a vector start from zero 396 Like other arrays, vectors use zero-origin indexing: the first
398and count up from there. 397element has index 0.
399 398
400 Vectors are printed with square brackets surrounding the elements. 399 Vectors are printed with square brackets surrounding the elements.
401Thus, a vector whose elements are the symbols @code{a}, @code{b} and 400Thus, a vector whose elements are the symbols @code{a}, @code{b} and
@@ -728,3 +727,96 @@ bv
728@noindent 727@noindent
729These results make sense because the binary codes for control-_ and 728These results make sense because the binary codes for control-_ and
730control-W are 11111 and 10111, respectively. 729control-W are 11111 and 10111, respectively.
730
731@node Rings
732@section Managing a Fixed-Size Ring of Objects
733
734@cindex ring data structure
735 A @dfn{ring} is a fixed-size data structure that supports insertion,
736deletion, rotation, and modulo-indexed reference and traversal. An
737efficient ring data structure is implemented by the @code{ring}
738package. It provides the functions listed in this section.
739
740 Note that several ``rings'' in Emacs, like the kill ring and the
741mark ring, are actually implemented as simple lists, @emph{not} using
742the @code{ring} package; thus the following functions won't work on
743them.
744
745@defun make-ring size
746This returns a new ring capable of holding @var{size} objects.
747@var{size} should be an integer.
748@end defun
749
750@defun ring-p object
751This returns @code{t} if @var{object} is a ring, @code{nil} otherwise.
752@end defun
753
754@defun ring-size ring
755This returns the maximum capacity of the @var{ring}.
756@end defun
757
758@defun ring-length ring
759This returns the number of objects that @var{ring} currently contains.
760The value will never exceed that returned by @code{ring-size}.
761@end defun
762
763@defun ring-elements ring
764This returns a list of the objects in @var{ring}, in order, newest first.
765@end defun
766
767@defun ring-copy ring
768This returns a new ring which is a copy of @var{ring}.
769The new ring contains the same (@code{eq}) objects as @var{ring}.
770@end defun
771
772@defun ring-empty-p ring
773This returns @code{t} if @var{ring} is empty, @code{nil} otherwise.
774@end defun
775
776 The newest element in the ring always has index 0. Higher indices
777correspond to older elements. Indices are computed modulo the ring
778length. Index @minus{}1 corresponds to the oldest element, @minus{}2
779to the next-oldest, and so forth.
780
781@defun ring-ref ring index
782This returns the object in @var{ring} found at index @var{index}.
783@var{index} may be negative or greater than the ring length. If
784@var{ring} is empty, @code{ring-ref} signals an error.
785@end defun
786
787@defun ring-insert ring object
788This inserts @var{object} into @var{ring}, making it the newest
789element, and returns @var{object}.
790
791If the ring is full, insertion removes the oldest element to
792make room for the new element.
793@end defun
794
795@defun ring-remove ring &optional index
796Remove an object from @var{ring}, and return that object. The
797argument @var{index} specifies which item to remove; if it is
798@code{nil}, that means to remove the oldest item. If @var{ring} is
799empty, @code{ring-remove} signals an error.
800@end defun
801
802@defun ring-insert-at-beginning ring object
803This inserts @var{object} into @var{ring}, treating it as the oldest
804element. The return value is not significant.
805
806If the ring is full, this function removes the newest element to make
807room for the inserted element.
808@end defun
809
810@cindex fifo data structure
811 If you are careful not to exceed the ring size, you can
812use the ring as a first-in-first-out queue. For example:
813
814@lisp
815(let ((fifo (make-ring 5)))
816 (mapc (lambda (obj) (ring-insert fifo obj))
817 '(0 one "two"))
818 (list (ring-remove fifo) t
819 (ring-remove fifo) t
820 (ring-remove fifo)))
821 @result{} (0 t one t "two")
822@end lisp
diff --git a/doc/lispref/strings.texi b/doc/lispref/strings.texi
index 49199d3e32f..bbb75f1474d 100644
--- a/doc/lispref/strings.texi
+++ b/doc/lispref/strings.texi
@@ -410,8 +410,13 @@ in case if @code{case-fold-search} is non-@code{nil}.
410@defun string= string1 string2 410@defun string= string1 string2
411This function returns @code{t} if the characters of the two strings 411This function returns @code{t} if the characters of the two strings
412match exactly. Symbols are also allowed as arguments, in which case 412match exactly. Symbols are also allowed as arguments, in which case
413their print names are used. 413the symbol names are used. Case is always significant, regardless of
414Case is always significant, regardless of @code{case-fold-search}. 414@code{case-fold-search}.
415
416This function is equivalent to @code{equal} for comparing two strings
417(@pxref{Equality Predicates}). In particular, the text properties of
418the two strings are ignored. But if either argument is not a string
419or symbol, an error is signaled.
415 420
416@example 421@example
417(string= "abc" "abc") 422(string= "abc" "abc")
@@ -422,10 +427,6 @@ Case is always significant, regardless of @code{case-fold-search}.
422 @result{} nil 427 @result{} nil
423@end example 428@end example
424 429
425The function @code{string=} ignores the text properties of the two
426strings. When @code{equal} (@pxref{Equality Predicates}) compares two
427strings, it uses @code{string=}.
428
429For technical reasons, a unibyte and a multibyte string are 430For technical reasons, a unibyte and a multibyte string are
430@code{equal} if and only if they contain the same sequence of 431@code{equal} if and only if they contain the same sequence of
431character codes and all these codes are either in the range 0 through 432character codes and all these codes are either in the range 0 through
diff --git a/doc/lispref/symbols.texi b/doc/lispref/symbols.texi
index 866a63c4cd9..0ee22b905b6 100644
--- a/doc/lispref/symbols.texi
+++ b/doc/lispref/symbols.texi
@@ -41,62 +41,58 @@ references another object:
41@table @asis 41@table @asis
42@item Print name 42@item Print name
43@cindex print name cell 43@cindex print name cell
44The @dfn{print name cell} holds a string that names the symbol for 44The symbol's name.
45reading and printing. See @code{symbol-name} in @ref{Creating Symbols}.
46 45
47@item Value 46@item Value
48@cindex value cell 47@cindex value cell
49The @dfn{value cell} holds the current value of the symbol as a 48The symbol's current value as a variable.
50variable. When a symbol is used as a form, the value of the form is the
51contents of the symbol's value cell. See @code{symbol-value} in
52@ref{Accessing Variables}.
53 49
54@item Function 50@item Function
55@cindex function cell 51@cindex function cell
56The @dfn{function cell} holds the function definition of the symbol. 52The symbol's function definition. It can also hold a symbol, a
57When a symbol is used as a function, its function definition is used in 53keymap, or a keyboard macro.
58its place. This cell is also used to make a symbol stand for a keymap
59or a keyboard macro, for editor command execution. Because each symbol
60has separate value and function cells, variables names and function names do
61not conflict. See @code{symbol-function} in @ref{Function Cells}.
62 54
63@item Property list 55@item Property list
64@cindex property list cell 56@cindex property list cell
65The @dfn{property list cell} holds the property list of the symbol. See 57The symbol's property list.
66@code{symbol-plist} in @ref{Property Lists}.
67@end table 58@end table
68 59
69 The print name cell always holds a string, and cannot be changed. The 60@noindent
70other three cells can be set individually to any specified Lisp object. 61The print name cell always holds a string, and cannot be changed.
71 62Each of the other three cells can be set to any Lisp object.
72 The print name cell holds the string that is the name of the symbol. 63
73Since symbols are represented textually by their names, it is important 64 The print name cell holds the string that is the name of a symbol.
74not to have two symbols with the same name. The Lisp reader ensures 65Since symbols are represented textually by their names, it is
75this: every time it reads a symbol, it looks for an existing symbol with 66important not to have two symbols with the same name. The Lisp reader
76the specified name before it creates a new one. (In GNU Emacs Lisp, 67ensures this: every time it reads a symbol, it looks for an existing
77this lookup uses a hashing algorithm and an obarray; see @ref{Creating 68symbol with the specified name before it creates a new one. To get a
78Symbols}.) 69symbol's name, use the function @code{symbol-name} (@pxref{Creating
79 70Symbols}).
80 The value cell holds the symbol's value as a variable 71
81(@pxref{Variables}). That is what you get if you evaluate the symbol as 72 The value cell holds a symbol's value as a variable, which is what
82a Lisp expression (@pxref{Evaluation}). Any Lisp object is a legitimate 73you get if the symbol itself is evaluated as a Lisp expression.
83value. Certain symbols have values that cannot be changed; these 74@xref{Variables}, for details about how values are set and retrieved,
84include @code{nil} and @code{t}, and any symbol whose name starts with 75including complications such as @dfn{local bindings} and @dfn{scoping
85@samp{:} (those are called @dfn{keywords}). @xref{Constant Variables}. 76rules}. Most symbols can have any Lisp object as a value, but certain
86 77special symbols have values that cannot be changed; these include
87 We often refer to ``the function @code{foo}'' when we really mean 78@code{nil} and @code{t}, and any symbol whose name starts with
88the function stored in the function cell of the symbol @code{foo}. We 79@samp{:} (those are called @dfn{keywords}). @xref{Constant
89make the distinction explicit only when necessary. In normal 80Variables}.
90usage, the function cell usually contains a function 81
91(@pxref{Functions}) or a macro (@pxref{Macros}), as that is what the 82 The function cell holds a symbol's function definition. Often, we
92Lisp interpreter expects to see there (@pxref{Evaluation}). Keyboard 83refer to ``the function @code{foo}'' when we really mean the function
93macros (@pxref{Keyboard Macros}), keymaps (@pxref{Keymaps}) and 84stored in the function cell of @code{foo}; we make the distinction
94autoload objects (@pxref{Autoloading}) are also sometimes stored in 85explicit only when necessary. Typically, the function cell is used to
95the function cells of symbols. 86hold a function (@pxref{Functions}) or a macro (@pxref{Macros}).
87However, it can also be used to hold a symbol (@pxref{Function
88Indirection}), keyboard macro (@pxref{Keyboard Macros}), keymap
89(@pxref{Keymaps}), or autoload object (@pxref{Autoloading}). To get
90the contents of a symbol's function cell, use the function
91@code{symbol-function} (@pxref{Function Cells}).
96 92
97 The property list cell normally should hold a correctly formatted 93 The property list cell normally should hold a correctly formatted
98property list (@pxref{Property Lists}), as a number of functions expect 94property list. To get a symbol's function cell, use the function
99to see a property list there. 95@code{symbol-plist}. @xref{Property Lists}.
100 96
101 The function cell or the value cell may be @dfn{void}, which means 97 The function cell or the value cell may be @dfn{void}, which means
102that the cell does not reference any object. (This is not the same 98that the cell does not reference any object. (This is not the same
@@ -104,57 +100,43 @@ thing as holding the symbol @code{void}, nor the same as holding the
104symbol @code{nil}.) Examining a function or value cell that is void 100symbol @code{nil}.) Examining a function or value cell that is void
105results in an error, such as @samp{Symbol's value as variable is void}. 101results in an error, such as @samp{Symbol's value as variable is void}.
106 102
107 The four functions @code{symbol-name}, @code{symbol-value}, 103 Because each symbol has separate value and function cells, variables
108@code{symbol-plist}, and @code{symbol-function} return the contents of 104names and function names do not conflict. For example, the symbol
109the four cells of a symbol. Here as an example we show the contents of 105@code{buffer-file-name} has a value (the name of the file being
110the four cells of the symbol @code{buffer-file-name}: 106visited in the current buffer) as well as a function definition (a
107primitive function that returns the name of the file):
111 108
112@example 109@example
113(symbol-name 'buffer-file-name) 110buffer-file-name
114 @result{} "buffer-file-name"
115(symbol-value 'buffer-file-name)
116 @result{} "/gnu/elisp/symbols.texi" 111 @result{} "/gnu/elisp/symbols.texi"
117(symbol-function 'buffer-file-name) 112(symbol-function 'buffer-file-name)
118 @result{} #<subr buffer-file-name> 113 @result{} #<subr buffer-file-name>
119(symbol-plist 'buffer-file-name)
120 @result{} (variable-documentation 29529)
121@end example 114@end example
122 115
123@noindent
124Because this symbol is the variable which holds the name of the file
125being visited in the current buffer, the value cell contents we see are
126the name of the source file of this chapter of the Emacs Lisp Manual.
127The property list cell contains the list @code{(variable-documentation
12829529)} which tells the documentation functions where to find the
129documentation string for the variable @code{buffer-file-name} in the
130@file{DOC-@var{version}} file. (29529 is the offset from the beginning
131of the @file{DOC-@var{version}} file to where that documentation string
132begins---see @ref{Documentation Basics}.) The function cell contains
133the function for returning the name of the file.
134@code{buffer-file-name} names a primitive function, which has no read
135syntax and prints in hash notation (@pxref{Primitive Function Type}). A
136symbol naming a function written in Lisp would have a lambda expression
137(or a byte-code object) in this cell.
138
139@node Definitions, Creating Symbols, Symbol Components, Symbols 116@node Definitions, Creating Symbols, Symbol Components, Symbols
140@section Defining Symbols 117@section Defining Symbols
141@cindex definitions of symbols 118@cindex definitions of symbols
142 119
143 A @dfn{definition} in Lisp is a special form that announces your 120 A @dfn{definition} is a special kind of Lisp expression that
144intention to use a certain symbol in a particular way. In Emacs Lisp, 121announces your intention to use a symbol in a particular way. It
145you can define a symbol as a variable, or define it as a function (or 122typically specifies a value or meaning for the symbol for one kind of
146macro), or both independently. 123use, plus documentation for its meaning when used in this way. Thus,
147 124when you define a symbol as a variable, you can supply an initial
148 A definition construct typically specifies a value or meaning for the 125value for the variable, plus documentation for the variable.
149symbol for one kind of use, plus documentation for its meaning when used
150in this way. Thus, when you define a symbol as a variable, you can
151supply an initial value for the variable, plus documentation for the
152variable.
153 126
154 @code{defvar} and @code{defconst} are special forms that define a 127 @code{defvar} and @code{defconst} are special forms that define a
155symbol as a global variable. They are documented in detail in 128symbol as a @dfn{global variable}---a variable that can be accessed at
156@ref{Defining Variables}. For defining user option variables that can 129any point in a Lisp program. @xref{Variables}, for details about
157be customized, use @code{defcustom} (@pxref{Customization}). 130variables. To define a customizable variable, use the
131@code{defcustom} macro, which also calls @code{defvar} as a subroutine
132(@pxref{Customization}).
133
134 In principle, you can assign a variable value to any symbol with
135@code{setq}, whether not it has first been defined as a variable.
136However, you ought to write a variable definition for each global
137variable that you want to use; otherwise, your Lisp program may not
138act correctly if it is evaluated with lexical scoping enabled
139(@pxref{Variable Scoping}).
158 140
159 @code{defun} defines a symbol as a function, creating a lambda 141 @code{defun} defines a symbol as a function, creating a lambda
160expression and storing it in the function cell of the symbol. This 142expression and storing it in the function cell of the symbol. This
@@ -171,15 +153,14 @@ both macro and function definitions are kept in the function cell, and
171that cell can hold only one Lisp object at any given time. 153that cell can hold only one Lisp object at any given time.
172@xref{Macros}. 154@xref{Macros}.
173 155
174 In Emacs Lisp, a definition is not required in order to use a symbol 156 As previously noted, Emacs Lisp allows the same symbol to be defined
175as a variable or function. Thus, you can make a symbol a global 157both as a variable (e.g.@: with @code{defvar}) and as a function or
176variable with @code{setq}, whether you define it first or not. The real 158macro (e.g.@: with @code{defun}). Such definitions do not conflict.
177purpose of definitions is to guide programmers and programming tools. 159
178They inform programmers who read the code that certain symbols are 160 These definition also act as guides for programming tools. For
179@emph{intended} to be used as variables, or as functions. In addition, 161example, the @kbd{C-h f} and @kbd{C-h v} commands create help buffers
180utilities such as @file{etags} and @file{make-docfile} recognize 162containing links to the relevant variable, function, or macro
181definitions, and add appropriate information to tag tables and the 163definitions. @xref{Name Help,,, emacs, The GNU Emacs Manual}.
182@file{DOC-@var{version}} file. @xref{Accessing Documentation}.
183 164
184@node Creating Symbols, Property Lists, Definitions, Symbols 165@node Creating Symbols, Property Lists, Definitions, Symbols
185@section Creating and Interning Symbols 166@section Creating and Interning Symbols
@@ -254,8 +235,8 @@ not work---only @code{intern} can enter a symbol in an obarray properly.
254 235
255@cindex CL note---symbol in obarrays 236@cindex CL note---symbol in obarrays
256@quotation 237@quotation
257@b{Common Lisp note:} In Common Lisp, a single symbol may be interned in 238@b{Common Lisp note:} Unlike Common Lisp, Emacs Lisp does not provide
258several obarrays. 239for interning a single symbol in several obarrays.
259@end quotation 240@end quotation
260 241
261 Most of the functions below take a name and sometimes an obarray as 242 Most of the functions below take a name and sometimes an obarray as
@@ -448,12 +429,13 @@ must be distinct.
448 429
449 Property lists are better than association lists for attaching 430 Property lists are better than association lists for attaching
450information to various Lisp function names or variables. If your 431information to various Lisp function names or variables. If your
451program keeps all of its associations in one association list, it will 432program keeps all such information in one association list, it will
452typically need to search that entire list each time it checks for an 433typically need to search that entire list each time it checks for an
453association. This could be slow. By contrast, if you keep the same 434association for a particular Lisp function name or variable, which
454information in the property lists of the function names or variables 435could be slow. By contrast, if you keep the same information in the
455themselves, each search will scan only the length of one property list, 436property lists of the function names or variables themselves, each
456which is usually short. This is why the documentation for a variable is 437search will scan only the length of one property list, which is
438usually short. This is why the documentation for a variable is
457recorded in a property named @code{variable-documentation}. The byte 439recorded in a property named @code{variable-documentation}. The byte
458compiler likewise uses properties to record those functions needing 440compiler likewise uses properties to record those functions needing
459special treatment. 441special treatment.