Subject: [clisp-list] mapcan bug

From: "Robert E. Brown" <[email-masked]>
Date: Fri Feb 7 09:42:44 2003

Using Allegro Common Lisp, CMUCL/SBCL, and Lispworks, the expression

     (mapcan #'identity (list 1))

evaluates to 1.  My copy of CLISP produces NIL -- see transcript below.  The
CLHS seems to indicate that 1 is the correct result.

                        bob

====================

loki <43>  clisp
  i i i i i i i       ooooo    o        ooooooo   ooooo   ooooo
  I I I I I I I      8     8   8           8     8     o  8    8
  I  \ `+' /  I      8         8           8     8        8    8
   \  `-+-'  /       8         8           8      ooooo   8oooo
    `-__|__-'        8         8           8           8  8
        |            8     o   8           8     o     8  8
  ------+------       ooooo    8oooooo  ooo8ooo   ooooo   8

Copyright (c) Bruno Haible, Michael Stoll 1992, 1993
Copyright (c) Bruno Haible, Marcus Daniels 1994-1997
Copyright (c) Bruno Haible, Pierpaolo Bernardi, Sam Steingold 1998
Copyright (c) Bruno Haible, Sam Steingold 1999-2002

[1]> (mapcan #'identity (list 1))
NIL
[2]>

---

From: Kaz Kylheku <[email-masked]>
Date: Fri Feb 7 10:23:06 2003

On Fri, 7 Feb 2003, Robert E. Brown wrote:

> Date: Fri, 07 Feb 2003 09:32:02 -0800
> From: Robert E. Brown <[email-masked]>
> To: [email-masked]
> Cc: [email-masked]
> Subject: [clisp-list] mapcan bug
> 
> 

Indeed, CLHS says that mapcan and mapcon work as if NCONC were applied
to the results of mapcar or maplist.

So mapcan, in the abstract, obeys this equivalence:

  (defun mapcan (fun &rest lists)
    (apply #'nconc (apply #'mapcar fun lists)))

if we ignore that there are practical limitations on the maximum
argument list size which make this a bad actual implementation.

So in your case, (mapcar #'identity (list 1)) would return (1), and so
you have (apply #'nconc (1)) or (nconc 1), which produces 1.

Not terribly useful, but you never know what might break if it doesn't
work.

---

From: Sam Steingold <[email-masked]>
Date: Sun Feb 9 14:25:03 2003

> * In message <[email-masked]>
> * On the subject of "[clisp-list] mapcan bug"
> * Sent on Fri, 07 Feb 2003 09:32:02 -0800
> * Honorable "Robert E. Brown" <[email-masked]> writes:
>

fixed in the CVS.
thanks.

-- 
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>
A PC without Windows is like ice cream without ketchup.