changeset 50415:b040b4e36f5e

(number-sequence): New function.
author Kenichi Handa <handa@m17n.org>
date Thu, 03 Apr 2003 02:43:11 +0000
parents 959a145fa4cd
children d6c0d7f63e86
files lisp/subr.el
diffstat 1 files changed, 16 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/subr.el	Thu Apr 03 01:59:08 2003 +0000
+++ b/lisp/subr.el	Thu Apr 03 02:43:11 2003 +0000
@@ -176,6 +176,22 @@
 	   (if (> n 0) (setcdr (nthcdr (- (1- m) n) x) nil))
 	   x))))
 
+(defun number-sequence (from &optional to)
+  "Return a sequence of numbers from FROM to TO (both inclusive) as a list.
+The Nth element of the list is (+ FROM N) where N counts from zero.
+If TO is nil, it defaults to FROM.
+If TO is less than FROM, the value is nil."
+  (if to
+      (if (< to from)
+	  (setq to (1- from)))
+    (setq to from))
+  (let* ((list (make-list (- (1+ to) from) from))
+	 (tail (cdr list)))
+    (while tail
+      (setcar tail (setq from (1+ from)))
+      (setq tail (cdr tail)))
+    list))
+
 (defun remove (elt seq)
   "Return a copy of SEQ with all occurrences of ELT removed.
 SEQ must be a list, vector, or string.  The comparison is done with `equal'."