[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: lispperformance was Re: problems with lisp
Guy Steele - Sun Microsystems Labs wrote:
> 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.
(loop for i in x
for j in y
collect (+ i j))
...doesn't look too bad yet. ;)
But the following would become really unhandy:
(defmacro vector-add (&rest vectors)
(when vectors
`(mapcar #'+ ,@vectors)))
or:
(defun vector-add (&rest args)
(reduce (lambda (&optional v1 v2)
(mapcar #'+ v1 v2))
args))
or:
(defun vector-add (&rest args)
(when (some #'identity args)
(cons (apply #'+ (mapcar #'car args))
(apply #'vector-add (mapcar #'cdr args)))))
I don't know how to do that with LOOP. So what? I am not purist. ;)
Pascal
--
Pascal Costanza University of Bonn
mailto:costanza@web.de Institute of Computer Science III
http://www.pascalcostanza.de Römerstr. 164, D-53117 Bonn (Germany)