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

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

Re: How to flatten a one-level-deep list?


From: Emanuel Berg
Subject: Re: How to flatten a one-level-deep list?
Date: Wed, 18 May 2016 23:07:53 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

Marcin Borkowski <mbork@mbork.pl> writes:

>>   (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 :)
>
> Thanks, that looks fine. Meanwhile, I went
> with a mapconcat nested within a mapconcat
> (the atoms I have are strings, and what
> I really need is concatenation of all of
> them).

C-h a flatten RET anyone?

    (defun message-flatten-list (list)
      "Return a new, flat list that contains all elements of LIST.

    \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
    => (1 2 3 4 5 6 7)"
      (cond ((consp list)
        (apply 'append (mapcar 'message-flatten-list list)))
       (list
        (list list))))

-- 
underground experts united .... http://user.it.uu.se/~embe8573
Emacs Gnus Blogomatic ......... http://user.it.uu.se/~embe8573/blogomatic
                   - so far: 33 Blogomatic articles -                   




reply via email to

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