Path: utzoo!utgpu!water!watmath!clyde!att!rutgers!mit-eddie!ll-xn!ames!amdcad!sun!pitstop!robv From: robv@pitstop.UUCP (Rob Vollum) Newsgroups: comp.lang.lisp Subject: Re: Summing a list Message-ID: <248@pitstop.UUCP> Date: 27 Oct 88 13:54:30 GMT References: <1131@amelia.nas.nasa.gov> <5671@eagle.ukc.ac.uk> <10794@srcsip.UUCP> Reply-To: robv@pitstop.UUCP (Rob Vollum) Organization: Sun Microsystems, Inc., Lexington, MA Lines: 27 In article <10794@srcsip.UUCP> rogers@eagle.UUCP (Brynn Rogers) writes: > I Have a silly question. I need to take the sum of a list > of numbers. > (SETQ NUMLIST '(1 2 3 6 7)) > This is quite simple, really, but what is the BEST way to do it? > I like: > > (EVAL (CONS '+ NUMLIST)) > > But someone else says this would be faster:: > [...iteration and recursion code deleted...] How about (apply #'+ numlist)? Besides being simple and clear, it is usually only a bit more overhead than an explicit call to the function being APPLY'd. In many cases, if the compiler is clever (and/or the programmer makes declarations about the function being APPLY'd), it is *no* additional overhead. Rob Vollum Sun Microsystems Lexington, MA sun!sunne!robv or rvollum@sun.com