• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Allegro X PCB Editor
  3. Remove item from list

Stats

  • Replies 5
  • Subscribers 159
  • Views 18707
  • Members are here 0
More Content

Remove item from list

archive
archive over 19 years ago

I'm trying to remove some items which both in two lists.
But the remove command doesn't work.

A='(0 1 2 3 4 5 6 7 8 9)
B='(1 3 5 7 9)
C=nil
foreach(item A
             if(member(item B) then
                C=remove(item A)
               )
            )


why the result is C= (0 1 2 3 4 5 6 7 8) not (0 2 4 6 8)?
how the remove works?

Who can help to tell me the reason or share me a right code to make it true~~
Thanks.


Originally posted in cdnusers.org by leonlee
  • Sign in to reply
  • Cancel
  • archive
    archive over 19 years ago

    I got the right result by using [b] copy [/b] and [b] remd [/b]

    A='(0 1 2 3 4 5 6 7 8 9)
    B='(1 3 5 7 9)
    C=copy(A)
    foreach(item A
    if(member(item B) then
    remd(item C)
    )
    )


    Originally posted in cdnusers.org by leonlee
    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • archive
    archive over 19 years ago

    Hi Leon,

    remove is a destructive function so you were correct to use copy.
    Another (faster) method is to use cons, to create a new list, or the slowish following method
    C = setof(item, A, !member(item, B))

    Cheers, Dave


    Originally posted in cdnusers.org by Dave Elder
    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • archive
    archive over 19 years ago

    Thanks Dave,
    I havn't think of !member,
    At first, I used member(item B)=nil, it doesn't work. Haha~~


    Originally posted in cdnusers.org by leonlee
    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • archive
    archive over 18 years ago

    below is what I use, it is very fast and does not go through unnecessary loops if you have duplicates in list A (or if all items in A have already been removed)

    A='(1 2 1 3 1 4 1 5)
    B='(1 3 5)

    procedure(SubstractList(B A)
    let((item)
    while(B && A
    item=car(B)
    B=cdr(B)
    A=remove(item A)
    )
    A
    )
    )

    Note that both lists are modified inside the procedure. This is ok since they are copies.
    If both lists are dbids, then creating another procedure that uses "req" instead of "remove" will be even faster.


    Originally posted in cdnusers.org by natebizu
    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • ajni
    ajni over 9 years ago
    remd does not remove the first element , if it is common in both.

    for a case when A='(1 2 3 4 5 6 )
    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Cadence Guidelines

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information