[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Inconsistent keywords for sequence functions
- To: DON%atc.bendix.com@RELAY.CS.NET
- Subject: Inconsistent keywords for sequence functions
- From: David A. Moon <Moon@STONY-BROOK.SCRC.Symbolics.COM>
- Date: Tue, 14 Apr 87 13:09 EDT
- Cc: common-lisp@SAIL.STANFORD.EDU
- In-reply-to: The message of 13 Apr 87 14:07 EDT from DON%atc.bendix.com@RELAY.CS.NET
Date: Mon, 13 Apr 87 14:07 EDT
Why do most of the sequence functions have the :key keyword but
reduce doesn't? Why isn't there a reduce-if and a reduce-if-not?
An example which came up recently is
(reduce #'+ box-contents :key #'weight)
which should return the sum of the weights of the objects in the box.
:key, -if, and -if-not only apply to functions that have :test arguments.
I can't imagine what reduce-if and reduce-if-not would do. I can see
what you want reduce :key to do, but I'm not sure :key is the right name
In retrospect, it might have been better language design to have fewer
options combined with stronger encouragement of implementations to
compile efficient code for nested function invocations, compiling out
temporary storage. Thus your example would be written:
(reduce #'+ (mapcar #'weight box-contents))
I realize quite well that there are a number of practical and philosophical
problems connected with actually doing this; please let's not start a long
discussion of them.