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

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

Re: Adding Lists/Sequences


From: Pascal J. Bourguignon
Subject: Re: Adding Lists/Sequences
Date: Tue, 23 Sep 2008 21:26:19 +0200
User-agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/22.2 (gnu/linux)

Thierry Volpiatto <thierry.volpiatto@gmail.com> writes:

> Nordlöw <per.nordlow@gmail.com> writes:
>
>> Is there a general function, say foo, that adds lists or, even better,
>> sequences together?
>>
>> I want this
>>   (foo '("a" "b") '("c" "d"))
>> to evaluate to
>>   '("a" "b" "c" "d")
>
> ,----
> | ELISP> (nconc '("a" "b" "c") '("d" "e" "f")) 
> | ("a" "b" "c" "d" "e" "f")
> `----

Very bad!

(defun bad-bad (tail)
   (nconc '(a b c) tail))

(bad-bad '(1 2 3)) --> (a b c 1 2 3)
(bad-bad '(4 5 6)) --> (a b c 1 2 3 4 5 6) ; !!!

NEVER use a destructive function on literal data!


> Note: `append' is not destructive

append is much better, but be careful that it shares the tail, so you
must consider the result as a literal data, unless you have consed the
tail yourself.


-- 
__Pascal_Bourguignon__


reply via email to

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