[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] trunk r117108: * src/fns.c (Freverse): Allow vectors, bool
From: |
Dmitry Antipov |
Subject: |
[Emacs-diffs] trunk r117108: * src/fns.c (Freverse): Allow vectors, bool vectors and strings. |
Date: |
Thu, 15 May 2014 06:09:32 +0000 |
User-agent: |
Bazaar (2.6b2) |
------------------------------------------------------------
revno: 117108
revision-id: address@hidden
parent: address@hidden
committer: Dmitry Antipov <address@hidden>
branch nick: trunk
timestamp: Thu 2014-05-15 10:01:46 +0400
message:
* src/fns.c (Freverse): Allow vectors, bool vectors and strings.
* doc/lispref/lists.texi (Building Cons Cells and Lists): Remove
description of `reverse' and generalize it...
* doc/lispref/sequences.texi (Sequences): ...for sequences here.
modified:
doc/lispref/ChangeLog changelog-20091113204419-o5vbwnq5f7feedwu-6155
doc/lispref/lists.texi lists.texi-20091113204419-o5vbwnq5f7feedwu-6192
doc/lispref/sequences.texi
sequences.texi-20091113204419-o5vbwnq5f7feedwu-6209
src/ChangeLog changelog-20091113204419-o5vbwnq5f7feedwu-1438
src/fns.c fns.c-20091113204419-o5vbwnq5f7feedwu-203
=== modified file 'doc/lispref/ChangeLog'
--- a/doc/lispref/ChangeLog 2014-05-14 17:15:15 +0000
+++ b/doc/lispref/ChangeLog 2014-05-15 06:01:46 +0000
@@ -1,3 +1,9 @@
+2014-05-15 Dmitry Antipov <address@hidden>
+
+ * lists.texi (Building Cons Cells and Lists): Remove
+ description of `reverse' and generalize it...
+ * sequences.texi (Sequences): ...for sequences here.
+
2014-05-14 Glenn Morris <address@hidden>
* files.texi (Changing Files): Mention with-file-modes.
=== modified file 'doc/lispref/lists.texi'
--- a/doc/lispref/lists.texi 2014-03-18 01:19:03 +0000
+++ b/doc/lispref/lists.texi 2014-05-15 06:01:46 +0000
@@ -601,25 +601,6 @@
resulting list. Instead, the sequence becomes the final @sc{cdr}, like
any other non-list final argument.
address@hidden reverse list
-This function creates a new list whose elements are the elements of
address@hidden, but in reverse order. The original argument @var{list} is
address@hidden altered.
-
address@hidden
address@hidden
-(setq x '(1 2 3 4))
- @result{} (1 2 3 4)
address@hidden group
address@hidden
-(reverse x)
- @result{} (4 3 2 1)
-x
- @result{} (1 2 3 4)
address@hidden group
address@hidden example
address@hidden defun
-
@defun copy-tree tree &optional vecp
This function returns a copy of the tree @code{tree}. If @var{tree} is a
cons cell, this makes a new cons cell with the same @sc{car} and
=== modified file 'doc/lispref/sequences.texi'
--- a/doc/lispref/sequences.texi 2014-03-09 11:36:51 +0000
+++ b/doc/lispref/sequences.texi 2014-05-15 06:01:46 +0000
@@ -217,6 +217,49 @@
@end example
@end defun
address@hidden reverse seq
address@hidden string reverse
address@hidden list reverse
address@hidden vector reverse
address@hidden sequence reverse
+This function creates a new sequence whose elements are the elements
+of @var{seq}, but in reverse order. The original argument @var{seq}
+is @emph{not} altered. Note that char-table cannot be reversed.
+
address@hidden
address@hidden
+(setq x '(1 2 3 4))
+ @result{} (1 2 3 4)
address@hidden group
address@hidden
+(reverse x)
+ @result{} (4 3 2 1)
+x
+ @result{} (1 2 3 4)
address@hidden group
address@hidden
+(setq x [1 2 3 4])
+ @result{} [1 2 3 4]
address@hidden group
address@hidden
+(reverse x)
+ @result{} [4 3 2 1]
+x
+ @result{} [1 2 3 4]
address@hidden group
address@hidden
+(setq x "xyzzy")
+ @result{} "xyzzy"
address@hidden group
address@hidden
+(reverse x)
+ @result{} "yzzyx"
+x
+ @result{} "xyzzy"
address@hidden group
address@hidden example
address@hidden defun
+
@node Arrays
@section Arrays
@cindex array
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog 2014-05-14 13:55:37 +0000
+++ b/src/ChangeLog 2014-05-15 06:01:46 +0000
@@ -1,3 +1,7 @@
+2014-05-15 Dmitry Antipov <address@hidden>
+
+ * fns.c (Freverse): Allow vectors, bool vectors and strings.
+
2014-05-14 Dmitry Antipov <address@hidden>
Minor cleanup for terminal setup.
=== modified file 'src/fns.c'
--- a/src/fns.c 2014-04-01 20:18:12 +0000
+++ b/src/fns.c 2014-05-15 06:01:46 +0000
@@ -1719,18 +1719,70 @@
}
DEFUN ("reverse", Freverse, Sreverse, 1, 1, 0,
- doc: /* Reverse LIST, copying. Return the reversed list.
+ doc: /* Return the reversed copy of list, vector, or string SEQ.
See also the function `nreverse', which is used more often. */)
- (Lisp_Object list)
+ (Lisp_Object seq)
{
Lisp_Object new;
- for (new = Qnil; CONSP (list); list = XCDR (list))
- {
- QUIT;
- new = Fcons (XCAR (list), new);
- }
- CHECK_LIST_END (list, list);
+ if (NILP (seq))
+ return Qnil;
+ else if (CONSP (seq))
+ {
+ for (new = Qnil; CONSP (seq); seq = XCDR (seq))
+ {
+ QUIT;
+ new = Fcons (XCAR (seq), new);
+ }
+ CHECK_LIST_END (seq, seq);
+ }
+ else if (VECTORP (seq))
+ {
+ ptrdiff_t i, size = ASIZE (seq);
+
+ new = make_uninit_vector (size);
+ for (i = 0; i < size; i++)
+ ASET (new, i, AREF (seq, size - i - 1));
+ }
+ else if (BOOL_VECTOR_P (seq))
+ {
+ ptrdiff_t i;
+ EMACS_INT nbits = bool_vector_size (seq);
+
+ new = make_uninit_bool_vector (nbits);
+ for (i = 0; i < nbits; i++)
+ bool_vector_set (new, i, bool_vector_bitref (seq, nbits - i - 1));
+ }
+ else if (STRINGP (seq))
+ {
+ ptrdiff_t size = SCHARS (seq), bytes = SBYTES (seq);
+
+ if (size == bytes)
+ {
+ ptrdiff_t i;
+
+ new = make_uninit_string (size);
+ for (i = 0; i < size; i++)
+ SSET (new, i, SREF (seq, size - i - 1));
+ }
+ else
+ {
+ unsigned char *p, *q;
+
+ new = make_uninit_multibyte_string (size, bytes);
+ p = SDATA (seq), q = SDATA (new) + bytes;
+ while (q > SDATA (new))
+ {
+ int ch, len;
+
+ ch = STRING_CHAR_AND_LENGTH (p, len);
+ p += len, q -= len;
+ CHAR_STRING (ch, q);
+ }
+ }
+ }
+ else
+ wrong_type_argument (Qsequencep, seq);
return new;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] trunk r117108: * src/fns.c (Freverse): Allow vectors, bool vectors and strings.,
Dmitry Antipov <=