Mercurial > emacs
comparison lispref/sequences.texi @ 54946:dc1950724cd9
Various clarifications.
author | Luc Teirlinck <teirllm@auburn.edu> |
---|---|
date | Sat, 17 Apr 2004 00:54:45 +0000 |
parents | 3839917a7e9e |
children | abb79c0e47ac 4c90ffeb71c5 |
comparison
equal
deleted
inserted
replaced
54945:70fd47f8342a | 54946:dc1950724cd9 |
---|---|
67 common property of all sequences is that they are ordered collections of | 67 common property of all sequences is that they are ordered collections of |
68 elements. This section describes functions that accept any kind of | 68 elements. This section describes functions that accept any kind of |
69 sequence. | 69 sequence. |
70 | 70 |
71 @defun sequencep object | 71 @defun sequencep object |
72 Returns @code{t} if @var{object} is a list, vector, | 72 Returns @code{t} if @var{object} is a list, vector, string, |
73 string, bool-vector, or char-table, @code{nil} otherwise. | 73 bool-vector, or char-table, @code{nil} otherwise. |
74 @end defun | 74 @end defun |
75 | 75 |
76 @defun length sequence | 76 @defun length sequence |
77 @cindex string length | 77 @cindex string length |
78 @cindex list length | 78 @cindex list length |
79 @cindex vector length | 79 @cindex vector length |
80 @cindex sequence length | 80 @cindex sequence length |
81 @cindex char-table length | 81 @cindex char-table length |
82 This function returns the number of elements in @var{sequence}. If | 82 This function returns the number of elements in @var{sequence}. If |
83 @var{sequence} is a cons cell that is not a list (because the final | 83 @var{sequence} is a dotted list, a @code{wrong-type-argument} error is |
84 @sc{cdr} is not @code{nil}), a @code{wrong-type-argument} error is | 84 signaled. Circular lists may cause an infinite loop. For a |
85 signaled. For a char-table, the value returned is always one more | 85 char-table, the value returned is always one more than the maximum |
86 than the maximum Emacs character code. | 86 Emacs character code. |
87 | 87 |
88 @xref{List Elements}, for the related function @code{safe-length}. | 88 @xref{Definition of safe-length}, for the related function @code{safe-length}. |
89 | 89 |
90 @example | 90 @example |
91 @group | 91 @group |
92 (length '(1 2 3)) | 92 (length '(1 2 3)) |
93 @result{} 3 | 93 @result{} 3 |
119 @end defun | 119 @end defun |
120 | 120 |
121 @defun elt sequence index | 121 @defun elt sequence index |
122 @cindex elements of sequences | 122 @cindex elements of sequences |
123 This function returns the element of @var{sequence} indexed by | 123 This function returns the element of @var{sequence} indexed by |
124 @var{index}. Legitimate values of @var{index} are integers ranging from | 124 @var{index}. Legitimate values of @var{index} are integers ranging |
125 0 up to one less than the length of @var{sequence}. If @var{sequence} | 125 from 0 up to one less than the length of @var{sequence}. If |
126 is a list, then out-of-range values of @var{index} return @code{nil}; | 126 @var{sequence} is a list, out-of-range values behave as for |
127 otherwise, they trigger an @code{args-out-of-range} error. | 127 @code{nth}. @xref{Definition of nth}. Otherwise, out-of-range values |
128 trigger an @code{args-out-of-range} error. | |
128 | 129 |
129 @example | 130 @example |
130 @group | 131 @group |
131 (elt [1 2 3 4] 2) | 132 (elt [1 2 3 4] 2) |
132 @result{} 3 | 133 @result{} 3 |
149 @error{} Args out of range: [1 2 3 4], -1 | 150 @error{} Args out of range: [1 2 3 4], -1 |
150 @end group | 151 @end group |
151 @end example | 152 @end example |
152 | 153 |
153 This function generalizes @code{aref} (@pxref{Array Functions}) and | 154 This function generalizes @code{aref} (@pxref{Array Functions}) and |
154 @code{nth} (@pxref{List Elements}). | 155 @code{nth} (@pxref{Definition of nth}). |
155 @end defun | 156 @end defun |
156 | 157 |
157 @defun copy-sequence sequence | 158 @defun copy-sequence sequence |
158 @cindex copying sequences | 159 @cindex copying sequences |
159 Returns a copy of @var{sequence}. The copy is the same type of object | 160 Returns a copy of @var{sequence}. The copy is the same type of object |
168 | 169 |
169 If the sequence is a string with text properties, the property list in | 170 If the sequence is a string with text properties, the property list in |
170 the copy is itself a copy, not shared with the original's property | 171 the copy is itself a copy, not shared with the original's property |
171 list. However, the actual values of the properties are shared. | 172 list. However, the actual values of the properties are shared. |
172 @xref{Text Properties}. | 173 @xref{Text Properties}. |
174 | |
175 This function does not work for dotted lists. Trying to copy a | |
176 circular list may cause an infinite loop. | |
173 | 177 |
174 See also @code{append} in @ref{Building Lists}, @code{concat} in | 178 See also @code{append} in @ref{Building Lists}, @code{concat} in |
175 @ref{Creating Strings}, and @code{vconcat} in @ref{Vector Functions}, | 179 @ref{Creating Strings}, and @code{vconcat} in @ref{Vector Functions}, |
176 for other ways to copy sequences. | 180 for other ways to copy sequences. |
177 | 181 |
470 @end defun | 474 @end defun |
471 | 475 |
472 @defun vconcat &rest sequences | 476 @defun vconcat &rest sequences |
473 @cindex copying vectors | 477 @cindex copying vectors |
474 This function returns a new vector containing all the elements of the | 478 This function returns a new vector containing all the elements of the |
475 @var{sequences}. The arguments @var{sequences} may be any kind of | 479 @var{sequences}. The arguments @var{sequences} may be true lists, |
476 arrays, including lists, vectors, or strings. If no @var{sequences} are | 480 vectors, strings or bool-vectors. If no @var{sequences} are given, an |
477 given, an empty vector is returned. | 481 empty vector is returned. |
478 | 482 |
479 The value is a newly constructed vector that is not @code{eq} to any | 483 The value is a newly constructed vector that is not @code{eq} to any |
480 existing vector. | 484 existing vector. |
481 | 485 |
482 @example | 486 @example |