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

Re: why tail recursion matters and why Java isn't it, was Re: lisp performance was Re: problems with lisp




   Date: Thu, 04 Sep 2003 19:02:07 +0200
   From: Pascal Costanza <costanza@iai.uni-bonn.de>
   To: Michael Sperber <sperber@informatik.uni-tuebingen.de>
   Cc: ll1-discuss@ai.mit.edu
   
   Michael Sperber wrote:
   ...
   > By explaining what you mean by "collect."  And by writing down the
   > order of the collection.  Try writing down solutions where the
   > accumulating operation isn't cons, but, say +, and, or -.  This should
   > be a matter of simple replacement, right?
   
   (loop for i in list sum i)
   
   (loop for i in list sum (- i))
   
   However, (apply '+ list) or (apply '- list) are more appropriate in this 
   regard. (In the case of - you get different results, but this is because 
   of the way - is defined.)
   
(- (apply #'+ list))

Which points up the fact that you may get greater
efficiency with (- (loop for i in list sum i))
than with (loop for i in list sum (- i)).

Now try writing down solutions where the accumulating
operation is vector-add, where

 (defun vector-add (x y) (mapcar #'+ x y))

So I write

 (loop for v in list vector-sum v)

right?  Um, well, no, here the paradigm breaks down a bit,
and things get more complicated after all.

--Guy Steele