Jump to content

Add the two lists


Kowal

Recommended Posts

Hi, I need a arguments function that sums the two lists.

Example

(setq lst1 (list (list 1 2 3 …) (list 2 3 4 …) (list 5 4 3 …) …))

(setq lst2 (list (list 4 4 4 …) (list 1 1 1 …) (list 3 3 3 …)  …))

Result

((5 6 7 …) (3 4 5 …) (8 7 6 …) …)

Lists are symmetric but have any length.

Link to comment
Share on other sites

(defun f ( l1 l2 ) (mapcar '(lambda ( x y ) (mapcar '+ x y)) l1 l2))

 

_$ (f '((1 2 3) (2 3 4) (5 4 3)) '((4 4 4) (1 1 1) (3 3 3)))
((5 6 7) (3 4 5) (8 7 6))

Link to comment
Share on other sites

Another way, recursive


(defun plus_lists (lst1 lst2 / )
;;FH 2009
(if (and lst1 
lst2)
(append (plus_lists (reverse (cdr (reverse lst1)))(reverse (cdr 
(reverse lst2))))
(list (mapcar '+ (last lst1) (last 
lst2)))
   )))))
;;usage : 
(setq summlst (plus_lists 
lst1 lst2))

Link to comment
Share on other sites

  • 3 years later...

Hello everyone...

I need your help.. I need to add the path to a dwg list...

(setq DWG_PATH_lst ("c:/test/")) ;

(setq DWG_List ("a1" "a2")) ;

the result must be a new list ===>>> ("c:/test/a1" "c:/test/a2")

 

please help... thank in advance

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...