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

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

Re: Adding Lists/Sequences


From: Thierry Volpiatto
Subject: Re: Adding Lists/Sequences
Date: Tue, 23 Sep 2008 22:48:46 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

pjb@informatimago.com (Pascal J. Bourguignon) writes:

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

Good tip, Thank you.

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

-- 
A + Thierry Volpiatto
Location: Saint-Cyr-Sur-Mer - France




reply via email to

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