From: Vinicius Jose Latorre Date: Sat, 5 Apr 2003 02:13:44 +0000 (+0000) Subject: Adjust number-sequence code X-Git-Tag: ttn-vms-21-2-B4~10632 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=0ed2c9b6d597f69cad6ac7a8d350f94a974920b7;p=emacs.git Adjust number-sequence code --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index d850e401c65..988976797ae 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,7 @@ +2003-04-04 Vinicius Jose Latorre + + * subr.el (number-sequence): Adjust code. + 2003-04-04 Stefan Monnier * textmodes/refill.el (refill-fill-paragraph-at): Undo last fix. diff --git a/lisp/subr.el b/lisp/subr.el index 0d3c9ea2497..17a7af41d4d 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -176,20 +176,23 @@ 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) +(defun number-sequence (from &optional to inc) "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. +INC is the increment used between numbers in the sequence. +So, the Nth element of the list is (+ FROM (* N INC)) where N counts from +zero. +If INC is nil, it defaults to 1 (one). 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 list)) - (while (setq tail (cdr tail)) - (setcar tail (setq from (1+ from)))) - list)) +If TO is less than FROM, the value is nil. +Note that FROM, TO and INC can be integer or float." + (if (not to) + (list from) + (or inc (setq inc 1)) + (let (seq) + (while (<= from to) + (setq seq (cons from seq) + from (+ from inc))) + (nreverse seq)))) (defun remove (elt seq) "Return a copy of SEQ with all occurrences of ELT removed.