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

Re: REDUCE args

    From: David C. Plummer <DCP@QUABBIN.SCRC.Symbolics.COM>
	Subject: REDUCE args

	Does anybody else wish that REDUCE took a KEY argument, similarly to MEMBER.

	(reduce #'+ list-of-objects :KEY #'object-quantity)

	would apply the function OBJECT-QUANTITY to each element of the
	list-of-objects before reducing it with +.

    Ditto.  I think GLS made some comment about this usage of :KEY being
    different than most.  Maybe that was in a different discussion.  There
    are possibly other related operations that should take KEY.  One could
    also add :TEST to avoid calling the operator on objects you don't want
    to.  Maybe this was Steele's point: Does the key apply before or after
    the test?  I think the intuitive usage is backwards from the other

It "being different than most" was my reaction, too.  In all other
cases, the :KEY argument is used to specify a "field" to be used for
selection (via :TEST or :TEST-NOT).  If :KEY were added to REDUCE in a
manner consistent with the rest of the language, it would only be useful
in conjunction with :TEST and :TEST-NOT, to either include or exclude
elements of the sequence from the reduction, which isn't what everyone
here seems to want.  Read pages 245-256.  Count one vote against, in the
name of maintaining the (somewhat pudding-like) consistency the language
has.  In the meantime, you can of course do something like:
	(reduce #'fun (map 'vector #'key sequence))