[PATCH] Call #'subseq from #'substring if arg not a string.

Aidan Kehoe kehoea at parhasard.net
Tue Mar 2 08:31:13 EST 2010


I’m not sure whether to bother with this, it may be that we do not want to
endorse the GNU practice.  Alternatively, we could give the bytecode to
#'subseq and define #'substring as an alias to it, which would add a bit of
generality at no real cost.

src/ChangeLog addition:

2010-03-02  Aidan Kehoe  <kehoea at parhasard.net>

	* fns.c (Fsubstring): If STRING is not a string, call #'subseq on
	it, for greater compatibility with GNU.


diff -r 4170f3809a28 src/fns.c
--- a/src/fns.c	Sun Feb 07 23:34:21 2010 +0000
+++ b/src/fns.c	Tue Mar 02 12:41:56 2010 +0000
@@ -952,6 +952,9 @@
 END may be nil or omitted; then the substring runs to the end of STRING.
 If START or END is negative, it counts from the end.
 Relevant parts of the string-extent-data are copied to the new string.
+
+For compatibility with GNU Emacs, STRING can also be another array type, in
+which case this function behaves like `subseq'.
 */
        (string, start, end))
 {
@@ -959,8 +962,14 @@
   Bytecount bstart, blen;
   Lisp_Object val;
 
-  CHECK_STRING (string);
+  CHECK_ARRAY (string);
   CHECK_INT (start);
+
+  if (!STRINGP (string))
+    {
+      return Fsubseq (string, start, end);
+    }
+
   get_string_range_char (string, start, end, &ccstart, &ccend,
 			 GB_HISTORICAL_STRING_BEHAVIOR);
   bstart = string_index_char_to_byte (string, ccstart);


-- 
“Apart from the nine-banded armadillo, man is the only natural host of
Mycobacterium leprae, although it can be grown in the footpads of mice.”
  -- Kumar & Clark, Clinical Medicine, summarising improbable leprosy research



More information about the XEmacs-Patches mailing list