Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!ukma!mailrus!ames!ai.etl.army.mil!hoey From: hoey@ai.etl.army.mil (Dan Hoey) Newsgroups: comp.lang.lisp Subject: Re: Summing a list Message-ID: <200@ai.etl.army.mil> Date: 31 Oct 88 17:04:44 GMT References: <10794@srcsip.UUCP> <10813@srcsip.UUCP> <249@pitstop.UUCP> <3780@cs.utexas.edu> <29856@think.UUCP> Reply-To: hoey@ai.etl.army.mil (Dan Hoey) Organization: Naval Research Lab, Washington, DC Lines: 22 In article <29856@think.UUCP> barmar@kulla.think.com.UUCP (Barry Margolin) writes: ... >I don't know why :KEY was left out. In my opinion, the best way to do >this currently is > (flet ((+-weight (x y) > (+ (box-weight x) (box-weight y)))) > (reduce #'+-weight ...)) The problem there is that if you do that with more than two elements, you end up trying to take the box-weight of the sum of two box-weights, and numbers aren't boxes. 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. Dan