+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Full Member Kowal's Avatar
    Using
    Civil 3D 2014
    Join Date
    Apr 2013
    Posts
    72

    Default Add the two lists

    Registered forum members do not see this ad.

    Hi, I need a arguments function that sums the two lists.
    Example
    Code:
    (setq lst1 (list (list 1 2 3 …) (list 2 3 4 …) (list 5 4 3 …) …))
    Code:
    (setq lst2 (list (list 4 4 4 …) (list 1 1 1 …) (list 3 3 3 …)  …))
    Result
    Code:
    ((5 6 7 …) (3 4 5 …) (8 7 6 …) …)
    Lists are symmetric but have any length.

  2. #2
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,227

    Default

    Code:
    (defun f ( l1 l2 ) (mapcar '(lambda ( x y ) (mapcar '+ x y)) l1 l2))
    Code:
    _$ (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))
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  3. #3
    Full Member Kowal's Avatar
    Using
    Civil 3D 2014
    Join Date
    Apr 2013
    Posts
    72

    Default

    Thank you.

  4. #4
    Super Member fixo's Avatar
    Computer Details
    fixo's Computer Details
    Operating System:
    Windows 7
    Motherboard:
    E7500
    CPU:
    Intel(R)Core(TM)2 DUO CPU 2.93HGz
    RAM:
    4098 Gb
    Graphics:
    1024 Gb
    Using
    AutoCAD 2009
    Join Date
    Jul 2005
    Location
    Thanks God, I'm far enough from Hitleropa
    Posts
    1,697

    Default

    Another way, recursive
    Code:
     
    (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))
    The soul is healed by being with children. - Fyodor Dostoyevsky, novelist (1821-1881)

  5. #5
    Forum Newbie
    Using
    MEP 2016
    Join Date
    Apr 2016
    Posts
    7

    Default

    Hello everyone...
    I need your help.. I need to add the path to a dwg list...
    (setq DWG_PATH_lst ("c:/test/")) ;<<<=== my dwg path, is a list also
    (setq DWG_List ("a1" "a2")) ;<<<=== my dwg list
    the result must be a new list ===>>> ("c:/test/a1" "c:/test/a2")

    please help... thank in advance

  6. #6
    Forum Newbie
    Using
    MEP 2016
    Join Date
    Apr 2016
    Posts
    7

    Default

    Registered forum members do not see this ad.

    got it...
    1. Make sure DWG_PATH_lst is a string...

    (setq New-DWG_List (mapcar '(lambda ( x ) (strcat DWG_PATH_lst x)) DWG_List))

Similar Threads

  1. To add two lists.
    By robierzo in forum AutoLISP, Visual LISP & DCL
    Replies: 10
    Last Post: 12th Sep 2012, 02:43 am
  2. Pin Lists
    By ko31505 in forum Electrical
    Replies: 1
    Last Post: 30th Sep 2010, 02:08 am
  3. Bullets and Lists
    By mr_mojo_risin in forum AutoCAD Beginners' Area
    Replies: 7
    Last Post: 17th Jun 2009, 09:33 am
  4. Lists?
    By ImaJayhawk in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 30th Jan 2004, 03:10 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts