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: Wed, 24 Sep 2008 09:09:08 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

David Kastrup <dak@gnu.org> 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")
>> `----
>>
>> Note: `append' is not destructive
>
> This is so bad that I can't believe it.
>
> (defun ugh () (nconc '("a" "b" "c") '("d" "e" "f")))
> (ugh) -> ("a" "b" "c" "d" "e" "f")
> (ugh) -> ("a" "b" "c" "d" "e" "f" . #3)
>
> The latter is a tail-cyclic list.
>
> (ugh) -> hangs
We speak of what is bad and very bad but didn't answer to what is good
or not, i send here a bad exemple as i constat i never used that in my
programs (nconc), idem for `nreverse'.And when i read again my commonlisp
book it say that is very delicate to use destructives functions.
So can you explain when it is good (if it is) to use these destructive
functions.

Here an example of the use of append that is safe.


,----
| ELISP> (setq A '(a b c))
| (a b c)
| 
| ELISP> (setq B '(1 2 3))
| (1 2 3)
| 
| ELISP> (defun quite-good (beg tail)
|          (append beg tail))
| quite-good
| ELISP> (quite-good A B)
| (a b c 1 2 3)
| 
| ELISP> (setq C (quite-good A B))
| (a b c 1 2 3)
| 
| ELISP> A
| (a b c)
| 
| ELISP> B
| (1 2 3)
| 
| ELISP> C
| (a b c 1 2 3)
`----

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




reply via email to

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