diff options
| author | Chong Yidong | 2009-02-22 21:07:15 +0000 |
|---|---|---|
| committer | Chong Yidong | 2009-02-22 21:07:15 +0000 |
| commit | c19ac817da3b287f55d8db57acb80e8f92c5f517 (patch) | |
| tree | 6d3615bdec50130c4c193f8f49c899ef33bbad24 | |
| parent | 61f660448f8d4d70239220de054ab46f296db954 (diff) | |
| download | emacs-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.texi | 99 |
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 | |||
| 13 | any array is a sequence. The common property that all sequences have is | 13 | any array is a sequence. The common property that all sequences have is |
| 14 | that each is an ordered collection of elements. | 14 | that 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 |
| 17 | of its elements. All the elements are accessible in constant time, but | 17 | elements. All the elements are accessible in constant time. The four |
| 18 | the length of an existing array cannot be changed. Strings, vectors, | 18 | types of arrays are strings, vectors, char-tables and bool-vectors. |
| 19 | char-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 |
| 22 | object; it is made of cons cells, one cell per element. Finding the | 21 | object; 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 | ||
| 51 | elements 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 |
| 226 | objects, called the elements of the array. Any element of an array may | 222 | objects, called the elements of the array. Any element of an array |
| 227 | be accessed in constant time. In contrast, an element of a list | 223 | may be accessed in constant time. In contrast, the time to access an |
| 228 | requires access time that is proportional to the position of the element | 224 | element of a list is proportional to the position of that element in |
| 229 | in the list. | 225 | the 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 |
| 233 | general array; its elements can be any Lisp objects. A string is a | 229 | Type}), @dfn{bool-vectors} (@pxref{Bool-Vector Type}), and |
| 234 | specialized array; its elements must be characters. Each type of array | 230 | @dfn{char-tables} (@pxref{Char-Table Type}). Vectors and char-tables |
| 235 | has its own read syntax. | 231 | can hold elements of any type, but strings can only hold characters, |
| 236 | @xref{String Type}, and @ref{Vector Type}. | 232 | and 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 |
| 394 | whose elements can be accessed in constant time. A @dfn{vector} is a | 390 | Lisp objects. (By contrast, the elements of a string can only be |
| 395 | general-purpose array of specified length; its elements can be any Lisp | 391 | characters. @xref{Strings and Characters}.) Vectors are used in |
| 396 | objects. (By contrast, a string can hold only characters as elements.) | 392 | Emacs for many purposes: as key sequences (@pxref{Key Sequences}), as |
| 397 | Vectors in Emacs are used for obarrays (vectors of symbols), and as part | 393 | symbol-lookup tables (@pxref{Creating Symbols}), as part of the |
| 398 | of keymaps (vectors of commands). They are also used internally as part | 394 | representation of a byte-compiled function (@pxref{Byte Compilation}), |
| 399 | of the representation of a byte-compiled function; if you print such a | 395 | and more. |
| 400 | function, 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 |
| 403 | and count up from there. | 398 | and 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 |
| 474 | This function returns a new vector containing all the elements of the | 469 | This 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, |
| 476 | vectors, strings or bool-vectors. If no @var{sequences} are given, an | 471 | vectors, strings or bool-vectors. If no @var{sequences} are given, an |
| 477 | empty vector is returned. | 472 | empty vector is returned. |
| @@ -525,18 +520,29 @@ character codes. Any valid character code, without modifiers, can be | |||
| 525 | used as an index in a char-table. You can access a char-table's | 520 | used as an index in a char-table. You can access a char-table's |
| 526 | elements with @code{aref} and @code{aset}, as with any array. In | 521 | elements with @code{aref} and @code{aset}, as with any array. In |
| 527 | addition, a char-table can have @dfn{extra slots} to hold additional | 522 | addition, a char-table can have @dfn{extra slots} to hold additional |
| 528 | data not associated with particular character codes. Char-tables are | 523 | data not associated with particular character codes. Like vectors, |
| 529 | constants when evaluated. | 524 | char-tables are constants when evaluated, and can hold elements of any |
| 525 | type. | ||
| 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 |
| 533 | has two purposes: to distinguish char-tables meant for different uses, | 529 | purposes: |
| 534 | and to control the number of extra slots. For example, display tables | 530 | |
| 535 | are char-tables with @code{display-table} as the subtype, and syntax | 531 | @itemize @bullet |
| 536 | tables are char-tables with @code{syntax-table} as the subtype. A valid | 532 | @item |
| 537 | subtype must have a @code{char-table-extra-slots} property which is an | 533 | The subtype provides an easy way to tell what the char-table is for. |
| 538 | integer between 0 and 10. This integer specifies the number of | 534 | For instance, display tables are char-tables with @code{display-table} |
| 539 | @dfn{extra slots} in the char-table. | 535 | as the subtype, and syntax tables are char-tables with |
| 536 | @code{syntax-table} as the subtype. The subtype can be queried using | ||
| 537 | the function @code{char-table-subtype}, described below. | ||
| 538 | |||
| 539 | @item | ||
| 540 | The subtype controls the number of @dfn{extra slots} in the | ||
| 541 | char-table. This number is specified by the subtype's | ||
| 542 | @code{char-table-extra-slots} symbol property, which should be an | ||
| 543 | integer between 0 and 10. If the subtype has no such symbol property, | ||
| 544 | the 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}. | |||
| 552 | whenever the char-table does not specify any other non-@code{nil} value. | 558 | whenever 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 |
| 555 | Return a newly created char-table, with subtype @var{subtype}. Each | 561 | Return a newly-created char-table, with subtype @var{subtype} (a |
| 556 | element is initialized to @var{init}, which defaults to @code{nil}. You | 562 | symbol). Each element is initialized to @var{init}, which defaults to |
| 557 | cannot 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 |
| 558 | created. | 564 | char-table is created. |
| 559 | 565 | ||
| 560 | There is no argument to specify the length of the char-table, because | 566 | There is no argument to specify the length of the char-table, because |
| 561 | all char-tables have room for any valid character code as an index. | 567 | all char-tables have room for any valid character code as an index. |
| 568 | |||
| 569 | If @var{subtype} has the @code{char-table-extra-slots} symbol | ||
| 570 | property, that specifies the number of extra slots in the char-table. | ||
| 571 | This 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 | ||
| 574 | extra slots. | ||
| 562 | @end defun | 575 | @end defun |
| 563 | 576 | ||
| 564 | @defun char-table-p object | 577 | @defun char-table-p object |
| 565 | This function returns @code{t} if @var{object} is a char-table, | 578 | This function returns @code{t} if @var{object} is a char-table, and |
| 566 | otherwise @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 |