[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
reduce should allow an accessor function to be specified
Date: Sat, 14 Nov 87 04:38:32 est
From: Mark Bromley <bromley@Think.COM>
Currently, the function is directly applied to the elements of the sequence.
This limits the utility of reduce. Summing the cars of a sequence of conses is
cumbersome using reduce, and is possible only because numbers can be
distinguished from conses at run time. E.g.
(reduce #'(lambda (a b) (+ (if (consp a) (car a) a) (if (consp b) (car b) b))) sequence)
It would be much more natural to be able to use the following
(reduce #'+ sequence :key #'car).
A better interim solution, except for the fact that it conses more,
would be to use
(reduce #'+ (map 'vector #'car sequence))
This doesn't depend on distinguishing previous results from input.