Re: novice: mapcan use?
- From: Bernd Schmitt <Bernd.Schmitt.News@xxxxxxx>
- Date: Sun, 28 Aug 2005 20:54:57 +0200
Hello Pascal,
Pascal Costanza wrote:
Bernd Schmitt wrote:
What you have in mind is that variables are updated to see new values. However, destructive functions in Lisp are allowed _not_ to update the corresponding variables. (There are good reasons for this.) So in general, you still need to use assignment via setq or setf to store the results in the right places. That's why it in general also doesn't really matter whether you use the destructive or non-destructive functions, except for optimization purposes.
As far as i understand (is there no apprev. for this AFAIU? I have the feeling I will use this term frequently ...), nconc is a destructive version of append, isnt't it? Nconc does change variables, if i understand the following in the right way:
CL-USER> (setq x '(1 2) y '(3 4)) (3 4) CL-USER> (nconc x y) (1 2 3 4) CL-USER> x (1 2 3 4)
So, when do I know, whether a variable can be used to catch the result of a destructive function (or was my example implementation dependent)?
[...] As mapcan iterates over the input list, it generates an intermediate list for the result, and that list is destructively changed.
Hm. So the result of CL-USER> (nconc '(1 2) '(3 4)) (1 2 3 4) is intermediate as well, right?
However, mapcan is somewhat old-fashioned. It's especially odd that the filtering function has to return the elements wrapped in lists.
It's clearer (IMHO) to use, for example, the LOOP macro instead:
(loop for x in '(a 2 b c 3 4 d 5) when (numberp x) collect x)
Ok. Loop is 90 pages away ... But as i see in the index, there is no collect ...
> It seems to me that you are using an "old-fashioned" book. It may be > better to go for something more recent, like Peter Seibel's "Practical > Common Lisp", David Lamkins's "Successful Lisp" or Peter Norvig's > "Paradigms of Artificial Intelligence Programming".
The reason why i read this book ("Programmieren in Common Lisp" O. Mayer) is, that I need a basic vocabulary build up in my mother language (german) to understand english computer texts (i am no computer science student, just a hobby coder in c/c++ tcl/tk). Otherwise things like "side-effect", "slot" ... would have no/wrong meaning to me. That is the main reason why somehow can not read pcl now.
Thank you for your reply, 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 .
- Follow-Ups:
- Re: novice: mapcan use?
- From: Rob Warnock
- Re: novice: mapcan use?
- From: Pascal Bourguignon
- Re: novice: mapcan use?
- From: Kent M Pitman
- Re: novice: mapcan use?
- From: Pascal Costanza
- Re: novice: mapcan use?
- References:
- novice: mapcan use?
- From: Bernd Schmitt
- Re: novice: mapcan use?
- From: Pascal Costanza
- novice: mapcan use?
- Prev by Date: Re: can anyone offer Lisp job?
- Next by Date: Re: novice: mapcan use?
- Previous by thread: Re: novice: mapcan use?
- Next by thread: Re: novice: mapcan use?
- Index(es):
Relevant Pages
|
|