|
From: Sam S. <sd...@gn...> - 2003-02-27 14:23:37
|
> * In message <200...@te...> > * On the subject of "[clisp-list] can mapcan do this?" > * Sent on Thu, 27 Feb 2003 08:25:42 -0500 > * Honorable Andrew Pimlott <an...@pi...> writes: > > This blew me away: > > > (setf c '((PIG2 BLUE4) (PIG1 RED))) > ((PIG2 BLUE4) (PIG1 RED)) > > (mapcan #'(lambda (p) (cdr (assoc p c))) '(PIG1 PIG2)) > (RED BLUE4) > > c > ((PIG2 RED BLUE4) (PIG1 BLUE4)) > > c has been modified, but not in the way I expected: the cdrs of > '(PIG2 BLUE4) and '(PIG1 RED) have been swapped. Does this mean > that the lambda really returns by reference? And what is the point > of this? It seems to me that whichever way you combine the two > lists, you need three pointers (one for the beginning of the first > list, one for the beginning of the second, and one to traverse the > first), so why pick the way that has unintuitive results? You did not specify which version of CLISP you are using. I must assume that it is not the current CVS head (which behaves the way you expect). > Moreover, the reference I am using > > http://www.lispworks.com/reference/HyperSpec/Body/f_mapc_.htm#mapcan > > indicates that (mapcar ...) is equivalent to (apply #'nconc (mapcar > ...)), and > > > (setf c '((PIG2 BLUE4) (PIG1 RED))) > ((PIG2 BLUE4) (PIG1 RED)) > > (apply #'nconc (mapcar #'(lambda (p) (cdr (assoc p c))) '(PIG1 PIG2))) > (RED BLUE4) > > c > ((PIG2 BLUE4) (PIG1 RED BLUE4)) > > So is mapcan allowed to do this? Or am I wrong in understanding that > the two must have the same side-effects? It may be argued both ways. At any rate, the next release will behave the way you expect. -- Sam Steingold (http://www.podval.org/~sds) running RedHat8 GNU/Linux <http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/> <http://www.mideasttruth.com/> <http://www.palestine-central.com/links.html> PI seconds is a nanocentury |