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

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

Re: `append' vs. `nconc'


From: Emanuel Berg
Subject: Re: `append' vs. `nconc'
Date: Thu, 31 Dec 2015 04:37:47 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

Teemu Likonen <tlikonen@iki.fi> writes:

> 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.

 I think I always used `append' as if it were

    (append list1 ... listn '())

probably the reason it never bit me was I never did
much with the lists returned.

> 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.

OK, so for example this:

(setq completion-ignored-extensions
      (append completion-ignored-extensions '(".bcf" ".run.xml")) )

Is better as:

    (nconc completion-ignored-extensions (list ".bcf" ".run.xml"))

?

>> 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.

OK.

-- 
underground experts united
http://user.it.uu.se/~embe8573




reply via email to

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