[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Tue, 17 Nov 2009 05:22:51 -0800 (PST)
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)))
;; Use: (sublist '(a b) 0 0)
;; Use: (sublist '(a b) 0 1)
;; Use: (sublist '(a b) 1 2)
;; Use: (sublist '(a b) 0 2)
- Extract sublists,