list c = list a - list b?

Discussion in 'AutoCAD' started by tsigwing, Jan 14, 2004.

  1. tsigwing

    tsigwing Guest

    I know there has to be a simple way to subtract the contents of one list from another. Any help?
     
    tsigwing, Jan 14, 2004
    #1
  2. any practical sample that i can take a look - to test.?

    --
    Get your free DraftTeam version 1.4 copy, just download it from here
    http://www.draftteam.com/draftteam/draftteam.zip or sent your request to


    Offer ends on Friday, January 23 of 2004


    from another. Any help?
     
    Luis Esquivel, Jan 14, 2004
    #2
  3. Responding to keyword "simple", and a fuzzy understanding what you mean
    "contents of one list from another" ...

    (setq
    list1 '(1 2 3 4 5)
    list2 '(2 3 4)
    )

    (vl-remove-if
    '(lambda (x) (member x list2))
    list1
    )

    returns (1 5)

    I know there has to be a simple way to subtract the contents of one list from
    another. Any help?
     
    michael puckett, Jan 14, 2004
    #3
  4. tsigwing

    Troy Guest

    That's it. Thanks.
     
    Troy, Jan 14, 2004
    #4
  5. tsigwing

    Adesu Guest

    Hi michael puckett , how about this below I would "(- list1 list2)"

    _$ (setq list1 '(1.9 2.8 3.7 4.8 5.7))

    (1.9 2.8 3.7 4.8 5.7)

    _$ (setq list2 '(1.1 2.2 3.3 4.1 5.5))

    (1.1 2.2 3.3 4.1 5.5)
     
    Adesu, Dec 29, 2004
    #5
  6. _$ (mapcar '- list1 list2)
    (0.8 0.6 0.4 0.7 0.2)


    --
    R. Robert Bell


    Hi michael puckett , how about this below I would "(- list1 list2)"

    _$ (setq list1 '(1.9 2.8 3.7 4.8 5.7))

    (1.9 2.8 3.7 4.8 5.7)

    _$ (setq list2 '(1.1 2.2 3.3 4.1 5.5))

    (1.1 2.2 3.3 4.1 5.5)
     
    R. Robert Bell, Dec 29, 2004
    #6
  7. tsigwing

    Adesu Guest

    Perfect ! ,thanks Bell
     
    Adesu, Dec 29, 2004
    #7
  8. tsigwing

    wkiernan Guest

    Or, alternatively,

    (setq list_c nil)
    (foreach el list_a
    (or (member el list_b)(setq list_c (cons el list_c)))
    )
     
    wkiernan, Dec 30, 2004
    #8
  9. tsigwing

    Adesu Guest

    ?????????????????????

    _ (setq list_a '(1.9 2.8 3.7 4.8 5.7))
    (1.9 2.8 3.7 4.8 5.7)
    _$ (setq list_b '(1.1 2.2 3.3 4.1 5.5))
    (1.1 2.2 3.3 4.1 5.5)
    _$ (setq list_c nil)
    nil
    _$ (foreach el list_a
    (or (member el list_b)(setq list_c (cons el list_c))))
    T
     
    Adesu, Dec 31, 2004
    #9
  10. tsigwing

    wkiernan Guest

    the expression itself returns T (that's the return value of or) but look at the value of list_c.
     
    wkiernan, Dec 31, 2004
    #10
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.