[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Appending to a list
From: |
steve-humphreys |
Subject: |
Re: Appending to a list |
Date: |
Sun, 13 Dec 2020 22:41:46 +0100 |
> Sent: Sunday, December 13, 2020 at 10:03 PM
> From: "Joost Kremers" <joostkremers@fastmail.fm>
> To: steve-humphreys@gmx.com
> Cc: help-gnu-emacs@gnu.org
> Subject: Re: Appending to a list
>
>
> On Sun, Dec 13 2020, steve-humphreys@gmx.com wrote:
> > Would appending to list like this be good?
> >
> > (setq bird '("Toucan" "King Fisher"))
> > (setq bird (append bird ("Swift") ))
>
> This should result in an error, because `("Swift")` isn't quoted. You'd need:
>
> (setq bird (append bird '("Swift")))
>
> But note that the last argument of `append` isn't copied, so it may not be a
> good idea to use a literal list.
>
> > Or does one customarily use other constructs for
> > adding to a list?
>
> `push` is what I would use:
>
> (push "Swift" bird)
>
> No need to use `setq` here.
>
> `push` won't check if the element is already in the list, though. You can use
> `cl-pushnew` in that case, but be sure to load the library it's in:
>
> (require 'cl-lib)
> (cl-pushnew "Swift" bird)
It won't be already in the list. Basically I just want to push entries
that are themselves lists, and just go with push push push ...
That was very helpful Joost.
> HTH
>
> --
> Joost Kremers
> Life has its moments
>
>
- Re: Appending to a list, (continued)
- Re: Appending to a list, steve-humphreys, 2020/12/14
- Re: Appending to a list, Emanuel Berg, 2020/12/14
- Re: Appending to a list, Michael Heerdegen, 2020/12/14
- Re: Appending to a list, Emanuel Berg, 2020/12/14
- Re: Appending to a list, steve-humphreys, 2020/12/14
- Re: Appending to a list, Emanuel Berg, 2020/12/14
- Re: Appending to a list, Joost Kremers, 2020/12/13
- Re: Appending to a list, Joost Kremers, 2020/12/13
Re: Appending to a list,
steve-humphreys <=