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: Thu, 31 Dec 2015 22:04:08 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5.50 (gnu/linux)

Emanuel Berg [2015-12-31 19:35:52+01] wrote:

> Teemu Likonen <tlikonen@iki.fi> writes:
>>     (setq foo (nconc (list '(a . 1) '(b . 2)) foo))

> What is the reason one has to use `list'? (I suppose the ` isn't safe,
> either.)

LIST function creates a fresh list when it is evaluated, usually at
runtime. The following applies to the Common Lisp language: Literal
objects created with ' ` (QUOTE ...) "string" etc. might be created at
compile time. Such objects might even be shared by all instances of such
literal object. Common Lisp compilers are allowed to do that. So, the
literal list '(a b c) in one place might actually become the very same
(as in EQ) object as literal '(a b c) in somewhere else. If you mutate
one object the results may show everywhere, which is not usually wanted.

Even though it may not apply to Emacs Lisp or all Common Lisp compilers
it's good habit to not mutate literally created objects. Be functional
with them! :-)

-- 
/// 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]