emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: request for a new function, say, `sequence'


From: Kenichi Handa
Subject: Re: request for a new function, say, `sequence'
Date: Thu, 3 Apr 2003 11:54:50 +0900 (JST)
User-agent: SEMI/1.14.3 (Ushinoya) FLIM/1.14.2 (Yagi-Nishiguchi) APEL/10.2 Emacs/21.2.92 (sparc-sun-solaris2.6) MULE/5.0 (SAKAKI)

In article <address@hidden>, Richard Stallman <address@hidden> writes:
>     Richard suggested `sequential-list' which, I think, is also
>     a good name.

> Thinking about it again, I think number-sequence might be a better name.

I've just installed it in subr.el.  I implemented it as below.

(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 list))
    (while (setq tail (cdr tail))
      (setcar tail (setq from (1+ from))))
    list))

If you think there's a better implementation, please improve
the code.

As for the spec of the function, I still have these
questions.

In Emacs, the word "number" includes a floating number.
Should we make number-sequence work also for floating
numbers?
Ex.  (number-sequence 1.5 4.4) => (1.5 2.5 3.5)
or
Ex.  (number-sequence 1.5 4.4) => (2 3 4)

Is it better to have the optional arg INC which specifies
how much to increment numbers.

---
Ken'ichi HANDA
address@hidden




reply via email to

[Prev in Thread] Current Thread [Next in Thread]