[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

Re: request for style evaluation-multiplying polynomials

William James

8/13/2015 4:50:00 AM

Rainer Joswig wrote:

> How about this one:
>
> (defun add-poly (a b)
> (loop for x = a then (rest x) and y = b then (rest y)
> while (or x y)
> collect (+ (or (first x) 0) (or (first y) 0))))
>
> CL-USER 3 > (add-poly '(1 2 3) '(1 2 3 4))
> (2 4 6 4)

Gauche Scheme:

(define (add-poly . xs)
(let1 size (apply max (map length xs))
(apply map + (concatenate (map (cut slices <> size #t 0) xs)))))

(add-poly '(2) '(3 4) '(5 6 7))
===>
(10 10 7)

--
I would hesitate to describe America as a nation at all in 1997,
because it is something very different: a polyethnic federation
administered by a single ruling class.... [T]he accumulated
rot in America has now reached a point where the pillars of
society itself are failing. --- Ambrose Evans-Pritchard