From: Clint Hyde
Subject: RE: Behaviour of MAPCAR
Date: 
Message-ID: <3ujl3d$e80@info-server.bbn.com>
In article <················@pan.firstperson.com> ··@firstperson.com (Frank Yellin) writes:

--> 
--> In article <··········@camelot.ccs.neu.edu> ·····@ccs.neu.edu (Michael
--> Tselman) writes: 
--> 
--> > Read page 30 of CLtL2. In particular it says (last paragraph):
--> > 	"... Most functions advertised to operate on lists expect to be given
--> > 	true lists. Throughout this book, unless otherwise specified, it is
--> > 	an error to pass a dotted list to a function that is specified to
--> > 	require a list as an argument."
--> 
--> And "it is an error" doesn't mean "should report an error".  
--> 
--> The implementation is free to handle "it is an error" any way it wants.

this has bothered me for years.  silently ignoring the error and
continuing is probably not what you want without explicitly saying so.

I'd guess that few functions would be speed compromised by adding the
(signal 'dotted-list-for-true-list-error) line somewhere, if, for
example, mapcar looked like this:

(defun mapcar (function &rest lists)
  (let ((num-args (length lists))
	temp
	result)
    (loop
      (if (is-each-element-listp lists)
	  (progn
	    (dolist (item lists)
	      (push (pop item) temp))
	    (push (funcall function (reverse temp)) result))
	(return)))
    (reverse result)))

add the error signal like this:

(defun mapcar (function &rest lists)
  (let ((num-args (length lists))
	temp
	result)
    (loop
      (if (is-each-element-listp lists)
	  (progn
	    (dolist (item lists)
	      (push (pop item) temp))
	    (push (funcall function (reverse temp)) result))

	;;RIGHT HERE
	(if *signal-dotted-list-errors*
	    (signal 'dotted-list-for-true-list-error))

	))
    (reverse result)))

(the above code doesn't actually work, but illustrates what I mean)

I have gotten bit by these non-obvious errors more than once, where the
book says "it's an error" meaning I goofed but lisp isn't going to tell
me. at least I don't get a core dump :(

 -- clint