Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!mailrus!bbn!rochester!pt.cs.cmu.edu!SKEF.SLISP.CS.CMU.EDU!skef From: skef@SKEF.SLISP.CS.CMU.EDU (Skef Wholey) Newsgroups: comp.lang.lisp Subject: Re: Summing a list Message-ID: <3467@pt.cs.cmu.edu> Date: 2 Nov 88 05:37:40 GMT References: <10794@srcsip.UUCP> <10813@srcsip.UUCP> <249@pitstop.UUCP> <200@ai.etl.army.mil> Sender: netnews@pt.cs.cmu.edu Organization: Carnegie-Mellon University, CS/RI Lines: 27 In article <200@ai.etl.army.mil>, hoey@ai.etl.army.mil (Dan Hoey) writes: > In article <29856@think.UUCP> barmar@kulla.think.com.UUCP (Barry Margolin) > writes: > >... I don't know why :KEY was left out ... > ... The ``right'' way is > (flet ((+-weight (x y) > (+ x (box-weight y)))) > (reduce #'+-weight ... :initial-value 0)) > Guy has explained the omission of :KEY based on some feature of REDUCE, > but I don't remember it being extremely convincing. ... The reasoning is this: in all other sequence functions, the :KEY function is applied to the operands of the test (either :TEST, :TEST-NOT, or the PREDICATE argument to an -IF or -IF-NOT function) -- see p. 247 of CLtL. To have :KEY do a kind of selection in REDUCE rather than a filtering operation would have destroyed this consistency. I don't know if this is "extremely convincing", but there is something to be said for keeping what consistency CL has... Oh, my vote for doing what you'd want to do: (reduce #'+ (map 'list #'box-weight ...)) Any "good" compiler should "do the right thing" with this. (Only 1/2 :-] here -- it is not really difficult to generate good code for stuff like that.) --Skef