From: Kenichi Handa Date: Thu, 3 Apr 2003 02:43:11 +0000 (+0000) Subject: (number-sequence): New function. X-Git-Tag: ttn-vms-21-2-B4~10660 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=abd9177af505ada770152a0055b0e6e3694c1da6;p=emacs.git (number-sequence): New function. --- diff --git a/lisp/subr.el b/lisp/subr.el index fab48872966..c5c94dfe01a 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -176,6 +176,22 @@ If N is bigger than the length of X, return X." (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'."