[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Adding Lists/Sequences
From: |
Drew Adams |
Subject: |
RE: Adding Lists/Sequences |
Date: |
Wed, 24 Sep 2008 08:49:38 -0700 |
> >>> 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.)
- Re: Adding Lists/Sequences, (continued)
- Message not available
- Re: Adding Lists/Sequences, David Kastrup, 2008/09/23
- Re: Adding Lists/Sequences, Thierry Volpiatto, 2008/09/24
- Re: Adding Lists/Sequences, Nikolaj Schumacher, 2008/09/24
- Re: Adding Lists/Sequences, Thierry Volpiatto, 2008/09/24
- RE: Adding Lists/Sequences, Drew Adams, 2008/09/24
- Re: Adding Lists/Sequences, Thierry Volpiatto, 2008/09/24
- Re: Adding Lists/Sequences, David Kastrup, 2008/09/24
- Re: Adding Lists/Sequences, Thierry Volpiatto, 2008/09/24
- RE: Adding Lists/Sequences,
Drew Adams <=
- Re: Adding Lists/Sequences, Thierry Volpiatto, 2008/09/24
- Message not available
- Re: Adding Lists/Sequences, Tim X, 2008/09/25
- Re: Adding Lists/Sequences, David Kastrup, 2008/09/25
- Re: Adding Lists/Sequences, Pascal J. Bourguignon, 2008/09/25