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

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

Re: Extract sublists


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

On Nov 17, 2:22 pm, Nordlöw <address@hidden> wrote:
> 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

Modified from org-sublist() but with 0-begin-indexing analogously with
substring.

/Nordlöw


reply via email to

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