unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Extract sublists
@ 2009-11-17 13:22 Nordlöw
  2009-11-17 13:24 ` Nordlöw
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Nordlöw @ 2009-11-17 13:22 UTC (permalink / raw)
  To: help-gnu-emacs

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)

Thanks,
Nordlöw


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2009-11-18 22:19 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-17 13:22 Extract sublists Nordlöw
2009-11-17 13:24 ` Nordlöw
2009-11-17 14:01 ` LanX
2009-11-17 14:09   ` LanX
2009-11-17 15:37 ` Ted Zlatanov
2009-11-18 11:16   ` Nordlöw
2009-11-18 22:19 ` Pascal J. Bourguignon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).