Re: mapcar use.



"verec" <verec@xxxxxxx> wrote in message
news:44012821$0$1168$5a6aecb4@xxxxxxxxxxxxxxxxxxxx
On 2006-02-26 03:33:21 +0000, "lispuser" <amit_h123@xxxxxxxxxxx> said:

(defun mul-list (list-1 list-2)
"Multiplies all elements of list-2 by the successive elements of list-1"
(let ((res nil))
(dolist (x list-1)
(setf res
(append res
(list
(mapcar (lambda (a)
(when a
(* a x)))
list-2)))))
res))

(defun doit (a b)
(loop for x in a collect (loop for y in b collect (* x y))))

But I'm sure more advanced lispers will come up with
lovely one-liners :-)

Well, no mapcars but it is one line!

--
Coby Beck
(remove #\Space "coby 101 @ bigpond . com")


.



Relevant Pages

  • Re: massive data analysis with lisp
    ... while res do ... (loop for k being the hash-keys in movidx using (hash-value v) ... (if (not (gethash custid assoctab)) ...
    (comp.lang.lisp)
  • Re: little isprime challenge
    ... Would it be faster to compute the square root of p, and use it as the loop ... The speed of your routine will be ... > res = .false. ... > COMMON block which contains an array holding the primes found so far. ...
    (comp.lang.fortran)
  • Re: massive data analysis with lisp
    ... while res do ... (loop for k being the hash-keys in movidx using (hash-value v) ... (if (not (gethash custid assoctab)) ...
    (comp.lang.lisp)
  • Re: Seaching across the top
    ... if not res is nothing then ... msgbox "Not found" ... It keeps running the loop until one ...
    (microsoft.public.excel.programming)
  • Re: Countnumberofdays while function = TRUE
    ... Loop while res <= 10 ... behind each cell in B. ...
    (microsoft.public.excel.programming)