diff options
| author | Richard M. Stallman | 1998-05-26 20:36:22 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1998-05-26 20:36:22 +0000 |
| commit | 74490e55dafccd6ebb1717c7144c5c36d6e0d838 (patch) | |
| tree | 4f1a85d0c9b3c6c189f963f4da4762ef00bf5dc2 | |
| parent | 1911e6e52c846c4a5bf744d850ec7061ff90c412 (diff) | |
| download | emacs-74490e55dafccd6ebb1717c7144c5c36d6e0d838.tar.gz emacs-74490e55dafccd6ebb1717c7144c5c36d6e0d838.zip | |
*** empty log message ***
| -rw-r--r-- | lispref/lists.texi | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/lispref/lists.texi b/lispref/lists.texi index bdc94dc015a..e20baaea5c2 100644 --- a/lispref/lists.texi +++ b/lispref/lists.texi | |||
| @@ -32,9 +32,10 @@ the whole list. | |||
| 32 | 32 | ||
| 33 | Lists in Lisp are not a primitive data type; they are built up from | 33 | 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 | 34 | @dfn{cons cells}. A cons cell is a data object that represents an |
| 35 | ordered pair. It records two Lisp objects, one labeled as the @sc{car}, | 35 | ordered pair. It holds, or ``points to,'' two Lisp objects, one labeled |
| 36 | and the other labeled as the @sc{cdr}. These names are traditional; see | 36 | as the @sc{car}, and the other labeled as the @sc{cdr}. These names are |
| 37 | @ref{Cons Cell Type}. @sc{cdr} is pronounced ``could-er.'' | 37 | traditional; see @ref{Cons Cell Type}. @sc{cdr} is pronounced |
| 38 | ``could-er.'' | ||
| 38 | 39 | ||
| 39 | A list is a series of cons cells chained together, one cons cell per | 40 | A list is a series of cons cells chained together, one cons cell per |
| 40 | element of the list. By convention, the @sc{car}s of the cons cells are | 41 | element of the list. By convention, the @sc{car}s of the cons cells are |
| @@ -82,10 +83,10 @@ made from two cons cells: | |||
| 82 | 83 | ||
| 83 | Each pair of boxes represents a cons cell. Each box ``refers to'', | 84 | Each pair of boxes represents a cons cell. Each box ``refers to'', |
| 84 | ``points to'' or ``contains'' a Lisp object. (These terms are | 85 | ``points to'' or ``contains'' a Lisp object. (These terms are |
| 85 | synonymous.) The first box, which is the @sc{car} of the first cons | 86 | synonymous.) The first box, which describes the @sc{car} of the first |
| 86 | cell, contains the symbol @code{tulip}. The arrow from the @sc{cdr} of | 87 | cons cell, contains the symbol @code{tulip}. The arrow from the |
| 87 | the first cons cell to the second cons cell indicates that the @sc{cdr} | 88 | @sc{cdr} box of the first cons cell to the second cons cell indicates |
| 88 | of the first cons cell points to the second cons cell. | 89 | that the @sc{cdr} of the first cons cell is the second cons cell. |
| 89 | 90 | ||
| 90 | The same list can be illustrated in a different sort of box notation | 91 | The same list can be illustrated in a different sort of box notation |
| 91 | like this: | 92 | like this: |
| @@ -668,8 +669,9 @@ different element. | |||
| 668 | 669 | ||
| 669 | @defun setcar cons object | 670 | @defun setcar cons object |
| 670 | This function stores @var{object} as the new @sc{car} of @var{cons}, | 671 | This function stores @var{object} as the new @sc{car} of @var{cons}, |
| 671 | replacing its previous @sc{car}. It returns the value @var{object}. | 672 | replacing its previous @sc{car}. In other words, it changes the |
| 672 | For example: | 673 | @sc{car} slot of @var{cons} to point to @var{object}. It returns the |
| 674 | value @var{object}. For example: | ||
| 673 | 675 | ||
| 674 | @example | 676 | @example |
| 675 | @group | 677 | @group |
| @@ -770,7 +772,9 @@ x2: | | |||
| 770 | 772 | ||
| 771 | @defun setcdr cons object | 773 | @defun setcdr cons object |
| 772 | This function stores @var{object} as the new @sc{cdr} of @var{cons}, | 774 | This function stores @var{object} as the new @sc{cdr} of @var{cons}, |
| 773 | replacing its previous @sc{cdr}. It returns the value @var{object}. | 775 | replacing its previous @sc{cdr}. In other words, it changes the |
| 776 | @sc{cdr} slot of @var{cons} to point to @var{object}. It returns the | ||
| 777 | value @var{object}. | ||
| 774 | @end defun | 778 | @end defun |
| 775 | 779 | ||
| 776 | Here is an example of replacing the @sc{cdr} of a list with a | 780 | Here is an example of replacing the @sc{cdr} of a list with a |
| @@ -797,7 +801,7 @@ x | |||
| 797 | You can delete elements from the middle of a list by altering the | 801 | You can delete elements from the middle of a list by altering the |
| 798 | @sc{cdr}s of the cons cells in the list. For example, here we delete | 802 | @sc{cdr}s of the cons cells in the list. For example, here we delete |
| 799 | the second element, @code{b}, from the list @code{(a b c)}, by changing | 803 | the second element, @code{b}, from the list @code{(a b c)}, by changing |
| 800 | the @sc{cdr} of the first cell: | 804 | the @sc{cdr} of the first cons cell: |
| 801 | 805 | ||
| 802 | @example | 806 | @example |
| 803 | @group | 807 | @group |
| @@ -968,7 +972,7 @@ each time you run it! Here is what happens: | |||
| 968 | This function reverses the order of the elements of @var{list}. | 972 | This function reverses the order of the elements of @var{list}. |
| 969 | Unlike @code{reverse}, @code{nreverse} alters its argument by reversing | 973 | Unlike @code{reverse}, @code{nreverse} alters its argument by reversing |
| 970 | the @sc{cdr}s in the cons cells forming the list. The cons cell that | 974 | the @sc{cdr}s in the cons cells forming the list. The cons cell that |
| 971 | used to be the last one in @var{list} becomes the first cell of the | 975 | used to be the last one in @var{list} becomes the first cons cell of the |
| 972 | value. | 976 | value. |
| 973 | 977 | ||
| 974 | For example: | 978 | For example: |
| @@ -985,7 +989,7 @@ x | |||
| 985 | @result{} (4 3 2 1) | 989 | @result{} (4 3 2 1) |
| 986 | @end group | 990 | @end group |
| 987 | @group | 991 | @group |
| 988 | ;; @r{The cell that was first is now last.} | 992 | ;; @r{The cons cell that was first is now last.} |
| 989 | x | 993 | x |
| 990 | @result{} (1) | 994 | @result{} (1) |
| 991 | @end group | 995 | @end group |
| @@ -1249,7 +1253,7 @@ for another way to add an element to a list stored in a variable. | |||
| 1249 | 1253 | ||
| 1250 | An @dfn{association list}, or @dfn{alist} for short, records a mapping | 1254 | An @dfn{association list}, or @dfn{alist} for short, records a mapping |
| 1251 | from keys to values. It is a list of cons cells called | 1255 | from keys to values. It is a list of cons cells called |
| 1252 | @dfn{associations}: the @sc{car} of each cell is the @dfn{key}, and the | 1256 | @dfn{associations}: the @sc{car} of each cons cell is the @dfn{key}, and the |
| 1253 | @sc{cdr} is the @dfn{associated value}.@footnote{This usage of ``key'' | 1257 | @sc{cdr} is the @dfn{associated value}.@footnote{This usage of ``key'' |
| 1254 | is not related to the term ``key sequence''; it means a value used to | 1258 | is not related to the term ``key sequence''; it means a value used to |
| 1255 | look up an item in a table. In this case, the table is the alist, and | 1259 | look up an item in a table. In this case, the table is the alist, and |