[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to flatten a one-level-deep list?
From: |
Pascal J. Bourguignon |
Subject: |
Re: How to flatten a one-level-deep list? |
Date: |
Wed, 18 May 2016 19:52:21 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) |
<tomas@tuxteam.de> writes:
> On Wed, May 18, 2016 at 07:12:56AM +0200, Marcin Borkowski wrote:
>> Hi,
>>
>> I have a list of lists of atoms, and I want to have a flat list
>> containing these atoms. I could use -flatten from dash.el, but I'd
>> prefer not to introduce such a dependency for this one function alone.
>> Is there anything *in core Emacs* to do it, or should I just write my
>> own version?
>
> (setq l '((a b c) (d e f) (g h i)))
> (apply 'append l)
> => (a b c d e f g h i)
>
> No idea whether performance or edge cases match your requirements,
> though :)
append will refer to the last list in that literal list, thus making the
result half literal. This may be a problem or not, depending on how you
use this result.
You can use concatenate (cl-concatenate) instead, if you want to copy
even the last subsequence:
(apply 'concatenate 'list l)
--> (a b c d e f g h i)
--
__Pascal Bourguignon__ http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: How to flatten a one-level-deep list?,
Pascal J. Bourguignon <=