all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Pascal J. Bourguignon" <pjb@informatimago.com>
To: help-gnu-emacs@gnu.org
Subject: Re: How to flatten a one-level-deep list?
Date: Wed, 18 May 2016 19:52:21 +0200	[thread overview]
Message-ID: <8737pffe3u.fsf@kuiper.lan.informatimago.com> (raw)
In-Reply-To: mailman.46.1463559697.6543.help-gnu-emacs@gnu.org

<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


      parent reply	other threads:[~2016-05-18 17:52 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-18  5:12 How to flatten a one-level-deep list? Marcin Borkowski
2016-05-18  8:21 ` tomas
2016-05-18  9:37   ` Marcin Borkowski
2016-05-18 21:07     ` Emanuel Berg
2016-05-20 12:17       ` Stefan Monnier
2016-05-20 15:01         ` Michael Heerdegen
2016-05-20 17:20           ` Marcin Borkowski
2016-05-20 17:54             ` Michael Heerdegen
2016-05-20 19:51               ` Marcin Borkowski
2016-05-20 22:14                 ` Michael Heerdegen
     [not found] ` <mailman.46.1463559697.6543.help-gnu-emacs@gnu.org>
2016-05-18 17:52   ` Pascal J. Bourguignon [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8737pffe3u.fsf@kuiper.lan.informatimago.com \
    --to=pjb@informatimago.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.