[comp.lang.lisp] The BEST way to sum a list

jcp@arizona.edu (John Peterson) (10/27/88)

The discussion comparing different ways to sum a list has missed an
important point.  Although the solution
  (apply '+ list)
is very elegent, it ignores a basic limitation of Common Lisp: 
call-arguments-limit.  This will not work (nor will eval) if the
list is longer than this value.  CLtL only states this limit must be at
least 50, not much of a list.  To be safe (or at least postable), either the
iterative solution or reduce should be used.  Also, note that this
brings up the issue of whether &rest should provide a freshly consed
list or not.  If it is, &rest would incur the additional overhead of a
list copy.  This issue is not addressed in CLtL.

(There are some very good implementation reasons for this limit.  Using
registers for parameter passing yields dramatic speedup, but only a
finite number of registers or psuedo registers are available.)


    John Peterson
    University of Arizona, Dept of Computer Science
    jcp@megaron.arizona.edu

    Think Granite

sfk@otter.hple.hp.com (Stephen Knight) (11/01/88)

jcp@arizona.edu (John Peterson) writes:
> The discussion [comparing different ways to sum a list]
> ignores a basic limitation of Common Lisp: call-arguments-limit. 

A very good point!  I would be interested in the typical values of this
system parameter.  Poplog CL has a default call-arguments-limit of 
536870912.  Is this unusual?

> (There are some very good implementation reasons for this limit.  Using
> registers for parameter passing yields dramatic speedup, but only a
> finite number of registers or psuedo registers are available.)

Although this is an explanation, I don't think it is an acceptable 
justification for strange limits like 50.  Sure, there are only a finite 
number of registers.  When they are all used up another parameter passing
mechanism is required.  This does not seem to be especially impractical or
even difficult.

I am reminded of a similar case in Pascal, where the guaranteed maximum size
of a set is something like 64 -- which is a crippling limitation in terms of
guaranteed portability.  In these cases one has to make a choice based on the
actual limits of popular compilers.

Steve Knight

hall@nvuxh.UUCP (Michael R Hall) (11/04/88)

In article <1350018@otter.hple.hp.com> sfk@otter.hple.hp.com (Stephen Knight) writes:
=jcp@arizona.edu (John Peterson) writes:
=> The discussion [comparing different ways to sum a list]
=> ignores a basic limitation of Common Lisp: call-arguments-limit. 
=
=A very good point!  I would be interested in the typical values of this
=system parameter.  Poplog CL has a default call-arguments-limit of 
=536870912.  Is this unusual?

Sun Lucid Common Lisp Development Environment 2.0.3 has 512 for the
call-arguments-limit value; I would guess that 536870912 is quite
unusual. [How about trying an experiment - call a function in Poplog
CL with 536870912 arguments and then call it with 536870913
arguments and see what happens...]
-- 
Michael R. Hall                               | Bell Communications Research
"I'm just a symptom of the moral decay that's | nvuxh!hall@bellcore.COM
gnawing at the heart of the country" -The The | bellcore!nvuxh!hall