aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorDmitry Antipov2014-05-15 18:59:02 +0400
committerDmitry Antipov2014-05-15 18:59:02 +0400
commitddc30c996a3d14e0163df6946ba96c9bcf73bd2f (patch)
tree6c0a2fafa8a124e0c6e12174321dc012226bb7a9 /doc
parent92491099f710794ee2be60721fae50d68c5ca162 (diff)
downloademacs-ddc30c996a3d14e0163df6946ba96c9bcf73bd2f.tar.gz
emacs-ddc30c996a3d14e0163df6946ba96c9bcf73bd2f.zip
* src/fns.c (Fnreverse): Allow vectors and bool vectors.
* doc/lispref/lists.texi (Building Cons Cells and Lists): Remove description of `nreverse' and generalize it... * doc/lispref/sequences.texi (Sequences): ...for sequences here. * tests/automated/fns-tests.el (fns-tests-nreverse) (fns-tests-nreverse-bool-vector): New tests.
Diffstat (limited to 'doc')
-rw-r--r--doc/lispref/ChangeLog2
-rw-r--r--doc/lispref/lists.texi52
-rw-r--r--doc/lispref/sequences.texi69
3 files changed, 70 insertions, 53 deletions
diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog
index d5fe02d2398..7d85e4059c9 100644
--- a/doc/lispref/ChangeLog
+++ b/doc/lispref/ChangeLog
@@ -1,7 +1,7 @@
12014-05-15 Dmitry Antipov <dmantipov@yandex.ru> 12014-05-15 Dmitry Antipov <dmantipov@yandex.ru>
2 2
3 * lists.texi (Building Cons Cells and Lists): Remove 3 * lists.texi (Building Cons Cells and Lists): Remove
4 description of `reverse' and generalize it... 4 description of `reverse' and `'nreverse' to generalize them...
5 * sequences.texi (Sequences): ...for sequences here. 5 * sequences.texi (Sequences): ...for sequences here.
6 6
72014-05-14 Glenn Morris <rgm@gnu.org> 72014-05-14 Glenn Morris <rgm@gnu.org>
diff --git a/doc/lispref/lists.texi b/doc/lispref/lists.texi
index 882dd440491..f724d5bd902 100644
--- a/doc/lispref/lists.texi
+++ b/doc/lispref/lists.texi
@@ -1124,58 +1124,6 @@ each time you run it! Here is what happens:
1124@end smallexample 1124@end smallexample
1125@end defun 1125@end defun
1126 1126
1127@defun nreverse list
1128@cindex reversing a list
1129 This function reverses the order of the elements of @var{list}.
1130Unlike @code{reverse}, @code{nreverse} alters its argument by reversing
1131the @sc{cdr}s in the cons cells forming the list. The cons cell that
1132used to be the last one in @var{list} becomes the first cons cell of the
1133value.
1134
1135 For example:
1136
1137@example
1138@group
1139(setq x '(a b c))
1140 @result{} (a b c)
1141@end group
1142@group
1143x
1144 @result{} (a b c)
1145(nreverse x)
1146 @result{} (c b a)
1147@end group
1148@group
1149;; @r{The cons cell that was first is now last.}
1150x
1151 @result{} (a)
1152@end group
1153@end example
1154
1155 To avoid confusion, we usually store the result of @code{nreverse}
1156back in the same variable which held the original list:
1157
1158@example
1159(setq x (nreverse x))
1160@end example
1161
1162 Here is the @code{nreverse} of our favorite example, @code{(a b c)},
1163presented graphically:
1164
1165@smallexample
1166@group
1167@r{Original list head:} @r{Reversed list:}
1168 ------------- ------------- ------------
1169| car | cdr | | car | cdr | | car | cdr |
1170| a | nil |<-- | b | o |<-- | c | o |
1171| | | | | | | | | | | | |
1172 ------------- | --------- | - | -------- | -
1173 | | | |
1174 ------------- ------------
1175@end group
1176@end smallexample
1177@end defun
1178
1179@defun sort list predicate 1127@defun sort list predicate
1180@cindex stable sort 1128@cindex stable sort
1181@cindex sorting lists 1129@cindex sorting lists
diff --git a/doc/lispref/sequences.texi b/doc/lispref/sequences.texi
index c96f1222f3f..da53990b449 100644
--- a/doc/lispref/sequences.texi
+++ b/doc/lispref/sequences.texi
@@ -260,6 +260,75 @@ x
260@end example 260@end example
261@end defun 261@end defun
262 262
263@defun nreverse seq
264@cindex reversing a list
265@cindex reversing a vector
266 This function reverses the order of the elements of @var{seq}.
267If @var{seq} is a list, @code{nreverse} alters its by reversing the @sc{cdr}s
268in the cons cells. The cons cell that used to be the last one in @var{seq}
269becomes the first cons cell of the value. If @var{seq} is a vector or
270bool vector, its items are placed in the same vector in a reversed order.
271
272 For example:
273
274@example
275@group
276(setq x '(a b c))
277 @result{} (a b c)
278@end group
279@group
280x
281 @result{} (a b c)
282(nreverse x)
283 @result{} (c b a)
284@end group
285@group
286;; @r{The cons cell that was first is now last.}
287x
288 @result{} (a)
289@end group
290@end example
291
292 To avoid confusion, we usually store the result of @code{nreverse}
293back in the same variable which held the original list:
294
295@example
296(setq x (nreverse x))
297@end example
298
299 Here is the @code{nreverse} of our favorite example, @code{(a b c)},
300presented graphically:
301
302@smallexample
303@group
304@r{Original list head:} @r{Reversed list:}
305 ------------- ------------- ------------
306| car | cdr | | car | cdr | | car | cdr |
307| a | nil |<-- | b | o |<-- | c | o |
308| | | | | | | | | | | | |
309 ------------- | --------- | - | -------- | -
310 | | | |
311 ------------- ------------
312@end group
313@end smallexample
314
315 For the vector, it is even simpler because you don't need setq:
316
317@example
318(setq x [1 2 3 4])
319 @result{} [1 2 3 4]
320(nreverse x)
321 @result{} [4 3 2 1]
322x
323 @result{} [4 3 2 1]
324@end example
325
326Note that unlike @code{reverse}, this function doesn't work with strings.
327Although you can alter string data by using @code{aset}, it is strongly
328encouraged to treat strings as immutable.
329
330@end defun
331
263@node Arrays 332@node Arrays
264@section Arrays 333@section Arrays
265@cindex array 334@cindex array