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

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

Re: `append' vs. `nconc'


From: Teemu Likonen
Subject: Re: `append' vs. `nconc'
Date: Wed, 30 Dec 2015 18:37:13 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5.50 (gnu/linux)

Emanuel Berg [2015-12-30 16:41:51+01] wrote:

> So what you are saying, if `append' is replaced by `nconc', the same
> thing happens, only one less list has to be created?

Given the following:

    (append list1 list2 list3 last)

    (nconc list1 list2 list3 last)

APPEND copies LIST1, LIST2 and LIST3 but not LAST. All original lists
remain untouched but LAST becomes part of the new list returned by
APPEND.

NCONC doesn't copy lists but modifies LIST1's, LIST2's and LIST3's last
cons's CDR to point to the next list. NCONC returnes the joined list.
Only LAST remains untouched.

> I have several appends in my source, is there a rule-of-thumb when to
> use `append' and when to use `nconc'?

You can use NCONC if it's safe to modify the lists, that is, you know
where the lists come from and know how they are used. Don't modify a
list created with '(...). Use (list ...) instead.

-- 
/// Teemu Likonen   - .-..   <https://github.com/tlikonen> //
// PGP: 4E10 55DC 84E9 DFF6 13D7 8557 719D 69D3 2453 9450 ///

Attachment: signature.asc
Description: PGP signature


reply via email to

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