REDUCE-ARGUMENT-EXTRACTIONREDUCE is the only one of the Common Lisp functions that modify or search lists and sequences which does not accept a :KEY argument. This complicates many uses of REDUCE.REDUCE to take a :KEY keyword described as follows:
If a :KEY argument is supplied, its value must be a function of one argument which will be used to extract the values to reduce. The :KEY function will be applied exactly once to each element of the sequence in the order implied by the reduction order but not to the value of the :INITIAL-VALUE argument, if any.
REDUCE to obtain the total of the ages of the possibly empty sequence of astronauts ASTROS, would currently require:
(REDUCE #'+ (MAP 'LIST #'PERSON-AGE ASTROS))
If this proposal is adopted, the same result could be obtained without creating a new list by:
(REDUCE #'+ ASTROS :KEY #'PERSON-AGE)
REDUCE would be useful much less cumbersome.REDUCE. Implementations which wish to use this as an opportunity to further optimize compiled calls to REDUCE will have to undertake more work (which would be much more difficult today).REDUCE will continue to be more difficult to use than other sequence functions on sequences of complex objects.REDUCE will become easier to use on sequences of complex objects. It will be easier for compilers to convert some calls to REDUCE into efficient loops.:KEY arguments are currently defined to be used for predicates, this proposal will implicitly broaden :KEY to support general extraction for any purpose.
Slightly improved in another way. Many common situations where REDUCE could be used would be easier to write and easier to later read.
:KEY. No one has objected to this change in the recent round of discussions.
There is some controversy over whether the "definition" of :KEY arguments on page 246 of CLtL really constitutes a definition or just an "unwritten rule".