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 19:59:33 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

"Drew Adams" <drew.adams@oracle.com> writes:

>> >>> explain when it is good (if it is) to use these 
>> >>> destructive functions.
>> >>
>> >> Generally, speed.  Non-destructive operations often create 
>> >> or copy a lot of new cons cells.
>> >
>> > Or when you want to share Lisp structure. A special case is 
>> > a circular structure, which shares part(s) of itself with itself.
>>
>> Can you provide a small example ? 
>
> (I meant "list structure", not "Lisp structure" BTW.)
>
> Real examples are best for this kind of thing. Grep for any of these 
> destructive
> functions in the Emacs installation `lisp' directory and its subdirectories:
> `nconc', `setcdr', `setcar', `delq', `(delete' (you'll get too many hits for
> just `delete'), `nreverse', or `sort' . 
>
> You will see in the code that such functions are used _judiciously_, never
> wantonly, and you will likely be able to see why, in context. Sometimes 
> comments
> explain the need for structure modification or sharing in a particular 
> context.
> If you don't understand the existing code, however, then I'd say stay away 
> from
> using list modification in your own code. 
>
> Also, see node `Modifying Lists' and its subnodes in the Elisp manual. They 
> give
> how-to examples and explain the use. Likewise, see node `Circular Objects'.
>
> If you really need to modify or share list structure for some reason, you will
> probably know about it. ;-) IOW, a real need will lead you to finding out more
> about it. If not, it's a good idea to stay away from using it. 
>
> And, other things being equal, it's generally a bad idea to try using
> modification just to speed up your code. IOW, don't try substituting `nconc' 
> for
> `append' liberally, thinking that you are optimizing things. It is more likely
> that you are breaking things. (Of course, breaking things can sometimes be a
> good way to learn, but beware that debugging code that is broken because of 
> list
> modification can be confusing.)
>
>
Thank you a lot for this, that's very instructive.
I already "grep" a lot source code in emacs to learn more, your code too ;)
-- 
A + Thierry Volpiatto
Location: Saint-Cyr-Sur-Mer - France




reply via email to

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