+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11
  1. #1
    Full Member
    Using
    AutoCAD 2006
    Join Date
    Aug 2012
    Location
    La Coruña. España
    Posts
    56

    Default To add two lists.

    Registered forum members do not see this ad.

    I need to add two lists. Add one to the list each member of the list2. The result would be the list3.
    Code:
    (setq lista2 '((0.0 14.127) (10.314 6.634) (6.374 -5.491) (-6.374 -5.491) (-10.314 6.634)))
    (setq lista1 '(150.0 200.0))
    The result:
    Code:
    lista3 ((150.0 214.127) (160.314 206.634).......(139.686 206.634))

  2. #2
    Forum Deity BlackBox's Avatar
    Using
    Civil 3D 2011
    Join Date
    Nov 2009
    Posts
    4,031

    Default

    Code:
    (append (list lista1) lista2)
    "Potential has a shelf life." - Margaret Atwood

  3. #3
    Full Member
    Using
    AutoCAD 2006
    Join Date
    Aug 2012
    Location
    La Coruña. España
    Posts
    56

    Default

    RenderMan, It's not right. You must use mapcar and lambda. But do not know how

  4. #4
    Forum Deity Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draftsman
    Discipline
    Mechanical
    Using
    AutoCAD 2014
    Join Date
    Oct 2009
    Location
    Lives in Abu Dhabi
    Posts
    2,664

    Default

    Code:
    (foreach x lista2 (setq l (cons (list (+ (car x) (car lista1)) (+ (cadr x) (cadr lista1))) l)))
    (reverse l)
    - When aim is being settled in my mind , I have to reach it and get it in hand whatever it costs and wherever it is and will never give up . Tharwat said

  5. #5
    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
    15,816

    Default

    Code:
    (mapcar '(lambda ( a ) (mapcar '+ a lista1)) lista2)
    Lee Mac Programming

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

    Just another Swamper

  6. #6
    Full Member
    Using
    AutoCAD 2006
    Join Date
    Aug 2012
    Location
    La Coruña. España
    Posts
    56

    Default

    O.K. Thanks to all three. Lee Mac option is what I wanted.
    regards

  7. #7
    Forum Deity BlackBox's Avatar
    Using
    Civil 3D 2011
    Join Date
    Nov 2009
    Posts
    4,031

    Default

    Respectfully, you neglected to specify the requirement for Mapcar and Lambda in your original post.

    I try not to suggest the more complex functions, when one neglects to demonstrate knowledge of the simpler (in this case Append)... Most certainly not because I think I know more than others, but simply that is how I learned.


    Second, had you tested the code I posted, you'd see that it does what you demonstrated in your original post (appending lista1 to the front of lista2).
    ... I stand corrected.

    Thankfully, other(s) have already answered your question, given the supplemental criteria.
    "Potential has a shelf life." - Margaret Atwood

  8. #8
    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
    15,816

    Default

    Quote Originally Posted by RenderMan View Post
    Second, had you tested the code I posted, you'd see that it does what you demonstrated in your original post (appending lista1 to the front of lista2).
    Look a little closer at the OP's requirement Renderman - the solution that you proposed is not equivalent to the others posted in this thread.
    Lee Mac Programming

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

    Just another Swamper

  9. #9
    Forum Deity BlackBox's Avatar
    Using
    Civil 3D 2011
    Join Date
    Nov 2009
    Posts
    4,031

    Default

    Post corrected.
    "Potential has a shelf life." - Margaret Atwood

  10. #10
    Full Member
    Using
    AutoCAD 2006
    Join Date
    Aug 2012
    Location
    La Coruña. España
    Posts
    56

    Default

    Registered forum members do not see this ad.

    Sorry. My English is the English translator of Google. It is archaic and poor, but I do not know more. I express myself best I can.
    Thank you.

Similar Threads

  1. Vb Lists And Combobox
    By russell84 in forum AutoLISP, Visual LISP & DCL
    Replies: 10
    Last Post: 14th Apr 2011, 07:46 pm
  2. Pin Lists
    By ko31505 in forum Electrical
    Replies: 1
    Last Post: 30th Sep 2010, 02:08 am
  3. Understanding Lists
    By CadProWannabe in forum AutoLISP, Visual LISP & DCL
    Replies: 14
    Last Post: 19th Jan 2010, 02:37 am
  4. Taking Lists Apart
    By The Buzzard in forum AutoLISP, Visual LISP & DCL
    Replies: 9
    Last Post: 6th Mar 2009, 09:23 pm
  5. 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