[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Appending to a list
From: |
Óscar Fuentes |
Subject: |
Re: Appending to a list |
Date: |
Sun, 13 Dec 2020 22:30:52 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
Joost Kremers <joostkremers@fastmail.fm> writes:
> 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)
This does not append.
> 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)
Isn't that the same as
(add-to-list bird "Swift" t)
?
- Appending to a list, steve-humphreys, 2020/12/13
- Re: Appending to a list, Joost Kremers, 2020/12/13
- Re: Appending to a list,
Óscar Fuentes <=
- Re: Appending to a list, steve-humphreys, 2020/12/13
- Re: Appending to a list, Stefan Monnier, 2020/12/13
- Re: Appending to a list, steve-humphreys, 2020/12/13
- Re: Appending to a list, Emanuel Berg, 2020/12/13
- Re: Appending to a list, steve-humphreys, 2020/12/13
- Re: Appending to a list, Emanuel Berg, 2020/12/13
- Re: Appending to a list, steve-humphreys, 2020/12/13
- Re: Appending to a list, Emanuel Berg, 2020/12/13
- Re: Appending to a list, steve-humphreys, 2020/12/13
- Re: Appending to a list, Michael Heerdegen, 2020/12/13