emacs-devel
[Top][All Lists]
Advanced

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

request for a new function, say, `sequence'


From: Kenichi Handa
Subject: request for a new function, say, `sequence'
Date: Sun, 23 Mar 2003 12:02:39 +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 the Indian languages support, we use this kind of
function repeatedly.  But, the function itself is generic
enough to be used in the other cases.  Can I install it in
subr.el (or simple.el)?

(defun sequence (from to type)
  "Return a sequence of type TYPE that contains numbers FROM to TO (inclusive).
TYPE must `list', `vector', or `string'.
If TYPE is `string', all numbers between FROM and TO must be valid
characters."
  (let ((len (1+ (- to from)))
        val)
    (if (>= len 0)
        (cond ((eq type 'list)
               (while (>= to from)
                 (setq val (cons to val)
                       to (1- to))))
              ((eq type 'vector)
               (setq val (make-vector len 0))
               (while (>= to from)
                 (aset val (- to from) to)
                 (setq to (1- to))))
              ((eq type 'string)
               (setq val (make-string len 0))
               (while (>= to from)
                 (aset val (- to from) to)
                 (setq to (1- to))))
              (t
               (error "Invalid type: %s" type))))
    val))

---
Ken'ichi HANDA
address@hidden




reply via email to

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