novice: mapcan use?



Hello,

I am currently learning lisp, so this is a novice basic question and I apologize for wrong use of words, I am still not used to some terms (hobby-coder in c/c++ tcl/tk).

It is about destructive functions. As far as I understand, destructive functions "destroy" their arguments, right?
So, if one wants to use their result, the argument should be a variable (somehow unsure which vocabulary to use, is symbol in lisp the same (in this regard) as variable in c?)?


The book, I am reading gives this as an example for the use of mapcan (a filter for numbers):

CL-USER> (mapcan #'(lambda (x)
		   (cond ((numberp x) (list x)) (t nil)))
		 '(a 2 b c 3 4 d 5)) ;; my problem
(2 3 4 5)

(sorry, I have to figure out how indentation is done with spaces in rpl of clisp (slime))

I do have problems with this.
What happens to '(a 2 b c 3 4 d 5)?
Is this a temporary object which will be changed?
If such a code would be in a source file, the code (the argument) would be changed?
Where are those objects stored?
When will their space be freed (by GC?)?



If my question shows deep misunderstanding of basic concepts of lisp, please feel free to give me the keyword I should have a closer look at.




Thanks for replies,
Bernd


-- https://gna.org/projects/mipisti - (microscope) picture stitching T_a_k_e__c_a_r_e__o_f__y_o_u_r__R_I_G_H_T_S. P_r_e_v_e_n_t__L_O_G_I_C--P_A_T_E_N_T_S http://www.ffii.org, http://www.nosoftwarepatents.org .



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?
    ... 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. ... 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. ...
    (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)