Subject: [clisp-list] can mapcan do this?

From: Andrew Pimlott <[email-masked]>
Date: Thu Feb 27 05:40:20 2003

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?

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?

Thanks,
Andrew

PS.  Please Cc: me on replies.

---

From: Sam Steingold <[email-masked]>
Date: Thu Feb 27 06:24:07 2003

> * In message <[email-masked]>
> * On the subject of "[clisp-list] can mapcan do this?"
> * Sent on Thu, 27 Feb 2003 08:25:42 -0500
> * Honorable Andrew Pimlott <[email-masked]> writes:
>
> This blew me away:
> 

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

> 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

---

From: Andrew Pimlott <[email-masked]>
Date: Thu Feb 27 07:53:03 2003

> You did not specify which version of CLISP you are using.

I really really meant to.  ;-)

I am using GNU CLISP 2.30 (released 2002-09-15) on Debian GNU/Linux
(compiled myself from the 2.30-6 Debian source package).

> I must assume that it is not the current CVS head (which behaves the way

Thanks for your reply.

Andrew