Re: novice: mapcan use?



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. Consider append vs. nconc, they both probably suck when it could actually be better to rearrange the code such that you only do one pass through your data.


Furthermore, the majority of the destructive functions are defined on conses/lists. It's better to get the whole picture that Lisp isn't "just" about list processing, but also has other data structures that are probably more important for creating efficient programs than destructive functions.

Pascal

--
OOPSLA'05 tutorial on generic functions & the CLOS Metaobject Protocol
++++ see http://p-cos.net/oopsla05-tutorial.html for more details ++++
.



Relevant Pages

  • Re: novice: mapcan use?
    ... destructive functions in Lisp are allowed _not_ to update the corresponding variables. ... Nconc does change variables, if i ... Don't use the destructive functions as your regular tools, and better forget completely about them in the beginning. ... The reason why i read this book is, that I need a basic vocabulary build up in my mother language to understand english computer texts. ...
    (comp.lang.lisp)
  • Re: novice: mapcan use?
    ... destructive functions in Lisp are allowed _not_ to update the corresponding variables. ... filtering function has to return the elements wrapped in lists. ... The reason why i read this book is, that I need a basic vocabulary build up in my mother language to understand english computer texts. ...
    (comp.lang.lisp)
  • Re: novice: mapcan use?
    ... In the beginning, it's better to learn about the higher level ways to express solutions in Lisp, and only care about optimization when you detect overheads in your programs that you want to avoid. ... However, destructive functions are "destructive" to the actual data structures, which means that they are allowed to side effect them - for example delete elements in lists. ...
    (comp.lang.lisp)
  • Re: very newbie
    ... >>(defun aggiungi (x L) ... > lisp is difficult but with a community like this become simpler. ... to aggiungi a variable containing the address of the first link in a ... destructive functions, one must often capture the result returned by the ...
    (comp.lang.lisp)