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

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

Re: Extract sublists


From: Pascal J. Bourguignon
Subject: Re: Extract sublists
Date: Wed, 18 Nov 2009 23:19:46 +0100
User-agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/22.3 (darwin)

Nordlöw <address@hidden> writes:

> 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)))

(require 'cl)
(list
 (subseq '(a b) 0 0)
 (subseq '(a b) 0 1)
 (subseq '(a b) 1 2)
 (subseq '(a b) 0 2))
--> (nil (a) (b) (a b))


-- 
__Pascal Bourguignon__


reply via email to

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