aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2009-02-22 21:07:15 +0000
committerChong Yidong2009-02-22 21:07:15 +0000
commitc19ac817da3b287f55d8db57acb80e8f92c5f517 (patch)
tree6d3615bdec50130c4c193f8f49c899ef33bbad24
parent61f660448f8d4d70239220de054ab46f296db954 (diff)
downloademacs-c19ac817da3b287f55d8db57acb80e8f92c5f517.tar.gz
emacs-c19ac817da3b287f55d8db57acb80e8f92c5f517.zip
(Sequences Arrays Vectors): Make introduction more concise.
(Arrays): Mention char-tables and bool-vectors too. (Vectors): Don't repeat information given in Arrays node. Link to nodes that explain the vector usage examples. (Char-Tables): Note that char-table elements can have arbitrary type. Explain effect of omitted char-table-extra-slots property.
-rw-r--r--doc/lispref/sequences.texi99
1 files changed, 56 insertions, 43 deletions
diff --git a/doc/lispref/sequences.texi b/doc/lispref/sequences.texi
index fe74a42b98b..1161e68cc35 100644
--- a/doc/lispref/sequences.texi
+++ b/doc/lispref/sequences.texi
@@ -13,10 +13,9 @@ types: lists and arrays. In other words, any list is a sequence, and
13any array is a sequence. The common property that all sequences have is 13any array is a sequence. The common property that all sequences have is
14that each is an ordered collection of elements. 14that each is an ordered collection of elements.
15 15
16 An @dfn{array} is a single primitive object that has a slot for each 16 An @dfn{array} is a fixed-length object with a slot for each of its
17of its elements. All the elements are accessible in constant time, but 17elements. All the elements are accessible in constant time. The four
18the length of an existing array cannot be changed. Strings, vectors, 18types of arrays are strings, vectors, char-tables and bool-vectors.
19char-tables and bool-vectors are the four types of arrays.
20 19
21 A list is a sequence of elements, but it is not a single primitive 20 A list is a sequence of elements, but it is not a single primitive
22object; it is made of cons cells, one cell per element. Finding the 21object; it is made of cons cells, one cell per element. Finding the
@@ -47,9 +46,6 @@ But it is possible to add elements to the list, or remove elements.
47@end group 46@end group
48@end example 47@end example
49 48
50 The elements of vectors and lists may be any Lisp objects. The
51elements of strings are all characters.
52
53@menu 49@menu
54* Sequence Functions:: Functions that accept any kind of sequence. 50* Sequence Functions:: Functions that accept any kind of sequence.
55* Arrays:: Characteristics of arrays in Emacs Lisp. 51* Arrays:: Characteristics of arrays in Emacs Lisp.
@@ -223,17 +219,17 @@ y @result{} [foo (69 2)]
223@cindex array 219@cindex array
224 220
225 An @dfn{array} object has slots that hold a number of other Lisp 221 An @dfn{array} object has slots that hold a number of other Lisp
226objects, called the elements of the array. Any element of an array may 222objects, called the elements of the array. Any element of an array
227be accessed in constant time. In contrast, an element of a list 223may be accessed in constant time. In contrast, the time to access an
228requires access time that is proportional to the position of the element 224element of a list is proportional to the position of that element in
229in the list. 225the list.
230 226
231 Emacs defines four types of array, all one-dimensional: @dfn{strings}, 227 Emacs defines four types of array, all one-dimensional:
232@dfn{vectors}, @dfn{bool-vectors} and @dfn{char-tables}. A vector is a 228@dfn{strings} (@pxref{String Type}), @dfn{vectors} (@pxref{Vector
233general array; its elements can be any Lisp objects. A string is a 229Type}), @dfn{bool-vectors} (@pxref{Bool-Vector Type}), and
234specialized array; its elements must be characters. Each type of array 230@dfn{char-tables} (@pxref{Char-Table Type}). Vectors and char-tables
235has its own read syntax. 231can hold elements of any type, but strings can only hold characters,
236@xref{String Type}, and @ref{Vector Type}. 232and bool-vectors can only hold @code{t} and @code{nil}.
237 233
238 All four kinds of array share these characteristics: 234 All four kinds of array share these characteristics:
239 235
@@ -390,14 +386,13 @@ are often useful for objects known to be arrays. @xref{Sequence Functions}.
390@section Vectors 386@section Vectors
391@cindex vector (type) 387@cindex vector (type)
392 388
393 Arrays in Lisp, like arrays in most languages, are blocks of memory 389 A @dfn{vector} is a general-purpose array whose elements can be any
394whose elements can be accessed in constant time. A @dfn{vector} is a 390Lisp objects. (By contrast, the elements of a string can only be
395general-purpose array of specified length; its elements can be any Lisp 391characters. @xref{Strings and Characters}.) Vectors are used in
396objects. (By contrast, a string can hold only characters as elements.) 392Emacs for many purposes: as key sequences (@pxref{Key Sequences}), as
397Vectors in Emacs are used for obarrays (vectors of symbols), and as part 393symbol-lookup tables (@pxref{Creating Symbols}), as part of the
398of keymaps (vectors of commands). They are also used internally as part 394representation of a byte-compiled function (@pxref{Byte Compilation}),
399of the representation of a byte-compiled function; if you print such a 395and more.
400function, you will see a vector in it.
401 396
402 In Emacs Lisp, the indices of the elements of a vector start from zero 397 In Emacs Lisp, the indices of the elements of a vector start from zero
403and count up from there. 398and count up from there.
@@ -471,7 +466,7 @@ each initialized to @var{object}.
471 466
472@defun vconcat &rest sequences 467@defun vconcat &rest sequences
473@cindex copying vectors 468@cindex copying vectors
474This function returns a new vector containing all the elements of the 469This function returns a new vector containing all the elements of
475@var{sequences}. The arguments @var{sequences} may be true lists, 470@var{sequences}. The arguments @var{sequences} may be true lists,
476vectors, strings or bool-vectors. If no @var{sequences} are given, an 471vectors, strings or bool-vectors. If no @var{sequences} are given, an
477empty vector is returned. 472empty vector is returned.
@@ -525,18 +520,29 @@ character codes. Any valid character code, without modifiers, can be
525used as an index in a char-table. You can access a char-table's 520used as an index in a char-table. You can access a char-table's
526elements with @code{aref} and @code{aset}, as with any array. In 521elements with @code{aref} and @code{aset}, as with any array. In
527addition, a char-table can have @dfn{extra slots} to hold additional 522addition, a char-table can have @dfn{extra slots} to hold additional
528data not associated with particular character codes. Char-tables are 523data not associated with particular character codes. Like vectors,
529constants when evaluated. 524char-tables are constants when evaluated, and can hold elements of any
525type.
530 526
531@cindex subtype of char-table 527@cindex subtype of char-table
532 Each char-table has a @dfn{subtype} which is a symbol. The subtype 528 Each char-table has a @dfn{subtype}, a symbol, which serves two
533has two purposes: to distinguish char-tables meant for different uses, 529purposes:
534and to control the number of extra slots. For example, display tables 530
535are char-tables with @code{display-table} as the subtype, and syntax 531@itemize @bullet
536tables are char-tables with @code{syntax-table} as the subtype. A valid 532@item
537subtype must have a @code{char-table-extra-slots} property which is an 533The subtype provides an easy way to tell what the char-table is for.
538integer between 0 and 10. This integer specifies the number of 534For instance, display tables are char-tables with @code{display-table}
539@dfn{extra slots} in the char-table. 535as the subtype, and syntax tables are char-tables with
536@code{syntax-table} as the subtype. The subtype can be queried using
537the function @code{char-table-subtype}, described below.
538
539@item
540The subtype controls the number of @dfn{extra slots} in the
541char-table. This number is specified by the subtype's
542@code{char-table-extra-slots} symbol property, which should be an
543integer between 0 and 10. If the subtype has no such symbol property,
544the char-table has no extra slots.
545@end itemize
540 546
541@cindex parent of char-table 547@cindex parent of char-table
542 A char-table can have a @dfn{parent}, which is another char-table. If 548 A char-table can have a @dfn{parent}, which is another char-table. If
@@ -552,18 +558,25 @@ specifies @code{nil}.
552whenever the char-table does not specify any other non-@code{nil} value. 558whenever the char-table does not specify any other non-@code{nil} value.
553 559
554@defun make-char-table subtype &optional init 560@defun make-char-table subtype &optional init
555Return a newly created char-table, with subtype @var{subtype}. Each 561Return a newly-created char-table, with subtype @var{subtype} (a
556element is initialized to @var{init}, which defaults to @code{nil}. You 562symbol). Each element is initialized to @var{init}, which defaults to
557cannot alter the subtype of a char-table after the char-table is 563@code{nil}. You cannot alter the subtype of a char-table after the
558created. 564char-table is created.
559 565
560There is no argument to specify the length of the char-table, because 566There is no argument to specify the length of the char-table, because
561all char-tables have room for any valid character code as an index. 567all char-tables have room for any valid character code as an index.
568
569If @var{subtype} has the @code{char-table-extra-slots} symbol
570property, that specifies the number of extra slots in the char-table.
571This should be an integer between 0 and 10; otherwise,
572@code{make-char-table} raises an error. If @var{subtype} has no
573@code{char-table-extra-slots} symbol property, the char-table has no
574extra slots.
562@end defun 575@end defun
563 576
564@defun char-table-p object 577@defun char-table-p object
565This function returns @code{t} if @var{object} is a char-table, 578This function returns @code{t} if @var{object} is a char-table, and
566otherwise @code{nil}. 579@code{nil} otherwise.
567@end defun 580@end defun
568 581
569@defun char-table-subtype char-table 582@defun char-table-subtype char-table