[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: mapcar and values interaction

   Date: Mon, 4 Mar 91 10:59:36 -0700
   From: drstrip@gnome.cs.sandia.gov (David R. Strip)
   Message-Id: <9103041759.AA05430@gnome.local>
   To: slug@ai.sri.com
   Subject: mapcar and values interaction
   Status: RWhy does (mapcar #'(lambda (x) (values)) '(1 2 3)) eval to

   (nil nil nil) and not ()?
   In general, how do you write a function for use in a mapcar so that
   it may or may not contribute to the resulting list?

Mapcar returns 1 value for each pass.  So mapcarring over the list '(1 2 3)
with a function of (values) returns 3 empty values, or (nil nil nil).

To avoid this, you could use something like remove-if-not to take all the
empties out after the mapcar is done.  Or, you could use something like MAPC
or DOLIST to push only the values you want onto a variable (like all values
that aren't nil).

I think by the definition of mapcar, everything will contribute a value to the
returned list, be it nil or not.
   ... Rick