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

Inconsistent keywords for sequence functions



    Date: Mon, 13 Apr 87 14:07 EDT
    From: DON%atc.bendix.com@RELAY.CS.NET

    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
for that.

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.