[Q] Change forms like (delq nil (mapcar ...)) to (mapcan ...).

Aidan Kehoe kehoea at parhasard.net
Sat Sep 18 12:17:20 EDT 2010


 Ar an seachtú lá déag de mí Méan Fómhair, scríobh Stephen J. Turnbull: 

 > QUERY
 > 
 > Aidan Kehoe writes:
 > 
 >  > Replace the O2N (delq nil (mapcar (lambda (W) (and X Y)) Z)) with
 >  > the ON (mapcan (lambda (W) (and X (list Y))) Z) in these files.
 > 
 > This can't work as written, can it?  If X is nil, if Y is nil, it will
 > wrap nil in a list and the nil will not be deleted.  I guess from a
 > quick look at the patch that it's expected that if X is non-nil, Y
 > will be non-nil, but are you sure?

It doesn’t quite work as written, you’re right. It was difficult to say
succinctly what I was doing, but I’m confident the actual changes are sane.

 > I'm also not convinced that this is necessarily faster if (length Z)
 > is small, as the mapcan version involves extra consing.

It involves fewer calls to #'cons, because the #'mapcar version has to
cons space for the nil elements as well as the non-nil elements.

-- 
“Apart from the nine-banded armadillo, man is the only natural host of
Mycobacterium leprae, although it can be grown in the footpads of mice.”
  -- Kumar & Clark, Clinical Medicine, summarising improbable leprosy research



More information about the XEmacs-Patches mailing list