Re: mapcar use.
- From: verec <verec@xxxxxxx>
- Date: Sun, 26 Feb 2006 04:01:37 +0000
On 2006-02-26 03:33:21 +0000, "lispuser" <amit_h123@xxxxxxxxxxx> said:
Hello all,
I am trying to use the mapcar function for the multiplication of 2
lists as :
(1 2) and (4 5 6)
so that the result which i get is
as
((4 5 6) (8 10 12))
I am still not gettin how to use eval and mapcar to achieve this...
Can somebody help me...
thanks
(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))
CL-USER 2 > (mul-list '(1 2) '(4 5 6))
((4 5 6) (8 10 12))
CL-USER 3 > (mul-list '(1 2 3) '(4 5 6))
((4 5 6) (8 10 12) (12 15 18))
But I'm sure more advanced lispers will come up with
lovely one-liners :-)
--
JFB
.
- Follow-Ups:
- Re: mapcar use.
- From: Carl Shapiro
- Re: mapcar use.
- From: Coby Beck
- Re: mapcar use.
- References:
- mapcar use.
- From: lispuser
- mapcar use.
- Prev by Date: mapcar use.
- Next by Date: Re: mapcar use.
- Previous by thread: mapcar use.
- Next by thread: Re: mapcar use.
- Index(es):
Relevant Pages
|
|