Subject: Re: Question about a numerical computation (possibly OT as Clisp question)
From: rpw3@rpw3.org (Rob Warnock)
Date: Mon, 30 Aug 2004 21:22:03 -0500
Newsgroups: comp.lang.lisp
Message-ID: <p7SdnUqfluRWfa7cRVn-oQ@speakeasy.net>
Pascal Bourguignon  <spam@mouse-potato.com> wrote:
+---------------
| Alain Picard <Alain.Picard@memetrics.com> writes:
| > Pascal Bourguignon <spam@mouse-potato.com> writes:
| > > [Personally, I prefer:
| > > (defun average (&rest args) (/ (apply (function +) args) (length args)))
| >
| >   ... (/ (reduce (function +) args) (length args))
| > This way you won't croak if you have more than CALL-ARGUMENTS-LIMIT args.
| 
| Note however that CALL-ARGUMENTS-LIMIT minimum is specified to be 50,
| so the "newbie" code could lead to problems only on a multi-line
| (average ...) sexp, or an (apply (function average) arg-list).
+---------------

Sounds like a great opportunity for a tutorial on compiler macros!
First, show the REDUCE version [which should always be the default],
then show a compiler macro that examines the length of the arg list
and if it's less than CALL-ARGUMENTS-LIMIT rewrites it into the APPLY
version.


-Rob

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