Re: novice: mapcan use?
- From: Peter Seibel <peter@xxxxxxxxxxxxxxx>
- Date: Wed, 31 Aug 2005 04:42:45 GMT
Kenny Tilton <ktilton@xxxxxxxxxx> writes:
> Pascal Costanza wrote:
>> Kenny Tilton wrote:
>>
>>>
>>> Pascal Costanza wrote:
>>>
>>>> It cannot be stressed enough: Don't use the destructive functions
>>>> as your regular tools, and better forget completely about them in
>>>> the beginning. They should be used exactly like the
>>>> non-destructive versions, and only ever for optimizations. There's
>>>> no other advantage in using them, and you should only optimize
>>>> those parts of your code that you have measured before so that you
>>>> know that optimizations actually buys you anything. Everything
>>>> else is a waste of your (valuable!) development time.
>>>
>>>
>>> Rubbish. That is a defense of ignorance, and a recipe for newbies
>>> writing code so painfully slow they abandon Lisp.
>>>
>>> /Always/ use the destructive version if one can get away with
>>> it. Understanding when one can get away with it is not so hard, and
>>> requires no more than the same understanding one needs anyway to
>>> program in Lisp.
>> Code doesn't get automagically faster by replacing non-destructive
>> functions with destructive ones.
>
> Uh, yeah, actually it does. You are simply defending ignorance. In any
> given situation I can safely use delete or I cannnot. If I can use
> delete, then using remove conses for no better reason other than to
> save me from thinking. Or, in the case of newbies, from learning Lisp.
Well it's possible that using a destructive (or, as I prefer,
"recycling") function will slow things down--by recycling old conses
you may move them out of the youngest generation in a generational
garbage collector where they could have been collected much more
efficiently than they will now. Or so I understand but IANAGCI.
At any rate, one interesting (to me anyway) stat I came across while
working on my book was the use of recycling functions in CLOCC: I
examined all the uses of recycling functions in CLOCC and found that
the PUSH, PUSH, NREVERSE idiom accounted for nearly half of all uses
of recycling functions and the next 30% were cases of immediately
reassigning a value back to the place containing the potentially
recycled value such as:
(setf foo (delete nil foo))
For whatever that's worth. Of course the real savings of PUSH/NREVERSE
comes from the PUSH not the NREVERSE. (I mean as opposed to doing
something awful like we've seen so many newbies do such as:
(do ((x ())) ((whatever) x) (setf x (append x (list (new-thing)))))
That is the Big-O complexity of PUSH, PUSH, NREVERSE would be the same
if you used REVERSE instead of NREVERSE.
-Peter
--
Peter Seibel * peter@xxxxxxxxxxxxxxx
Gigamonkeys Consulting * http://www.gigamonkeys.com/
Practical Common Lisp * http://www.gigamonkeys.com/book/
.
- Follow-Ups:
- Re: novice: mapcan use?
- From: anamax
- Re: novice: mapcan use?
- From: Ulrich Hobelmann
- Re: novice: mapcan use?
- References:
- novice: mapcan use?
- From: Bernd Schmitt
- Re: novice: mapcan use?
- From: Pascal Costanza
- Re: novice: mapcan use?
- From: Bernd Schmitt
- Re: novice: mapcan use?
- From: Pascal Costanza
- Re: novice: mapcan use?
- From: Kenny Tilton
- Re: novice: mapcan use?
- From: Pascal Costanza
- Re: novice: mapcan use?
- From: Kenny Tilton
- novice: mapcan use?
- Prev by Date: Re: Concentration in OCaml
- Next by Date: Re: ASDF: optimization settings and other enhancements
- Previous by thread: Re: novice: mapcan use?
- Next by thread: Re: novice: mapcan use?
- Index(es):
Relevant Pages
|