[Top][All Lists]

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

Extract sublists

From: Nordlöw
Subject: Extract sublists
Date: Tue, 17 Nov 2009 05:22:51 -0800 (PST)
User-agent: G2/1.0

Is there a function for extracting sublists of lists?

If not here is my suggestion for inclusion in Emacs.

(defun sublist (list from to)
  "Return a sublist of LIST, from FROM to TO.
Counting starts at 0. Like `substring' but for lists."
  (let (rtn (c from))
    (setq list (nthcdr from list))
    (while (and list (< c to))
      (push (pop list) rtn)
      (setq c (1+ c)))
    (nreverse rtn)))
;; Use: (sublist '(a b) 0 0)
;; Use: (sublist '(a b) 0 1)
;; Use: (sublist '(a b) 1 2)
;; Use: (sublist '(a b) 0 2)


reply via email to

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