Subject: Re: Another FAQ (my brain isn't working)
From: rpw3@rpw3.org (Rob Warnock)
Date: Fri, 28 Mar 2003 05:59:41 -0600
Newsgroups: comp.lang.lisp
Message-ID: <gfKdnWZ-ZcOwpBmjXTWc-w@speakeasy.net>
Marco Antoniotti  <marcoxa@cs.nyu.edu> wrote:
+---------------
|   (defmacro plus (&rest args) `(+ ,@args))
| Now I have a list
|   (defvar *numbers* (list 1 2 3))
| You know the question.  How do I do the equivalent of
|   (apply #'+ *numbers*)
+---------------

At the cost of losing the efficiency of the macro (assuming
the actual case is much more complex than you've given here),
you could always do:

    (reduce #'(lambda (x y) (plus x y)) *numbers*)

Which brings up a side point: Given that I use the Unix command
"xargs" with some frequency (expecially with the "-n" option),
it's often been frustrating to me that REDUCE doesn't accept a
keyword parameter specifying the maximum number of arguments that
can be passed to its first parameter per call, defaulting to 2.
Then you could portably chunk through *huge* reductions N args
at a time. In the limit (pardon the pun) even saying:

    (reduce #'+ *numbers* :max-args call-arguments-limit)

[Useful for Lisps with values of "call-arguments-limit" close to
the minimums required by the standard.]

Was this considered at all when REDUCE was standardized?


-Rob

-----
Rob Warnock, PP-ASEL-IA		<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607