help-gnu-emacs
[Top][All Lists]
Advanced

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

Index of element in a sequence


From: Greg Hill
Subject: Index of element in a sequence
Date: Wed, 27 Nov 2002 11:07:48 -0800

Are there any built-in functions that provide the equivalent of the following lisp routines?

(defun indq (value seq)
  "Return the index number of VALUE in sequence SEQ, using eq for test.
Return nil if VALUE does not exist in SEQ."
  (let ((ix 0) (len (length seq)))
    (catch 'indq
      (while (< ix len)
        (if (eq (elt seq ix) value)
            (throw 'indq ix)
          (setq ix (1+ ix)) ) ) ) ))


(defun index (value seq)
  "Return the index number of VALUE in sequence SEQ, using equal for test.
Return nil if VALUE does not exist in SEQ."
  (let ((ix 0) (len (length seq)))
    (catch 'index
      (while (< ix len)
        (if (equal (elt seq ix) value)
            (throw 'index ix)
          (setq ix (1+ ix)) ) ) ) ))

--Greg




reply via email to

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