• 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. Custom IC SKILL
  3. Look for matches between 2 lists

Stats

  • Replies 2
  • Subscribers 143
  • Views 889
  • Members are here 0

Look for matches between 2 lists

vtboy51
vtboy51 2 months ago

I need to compare all items in list1 against the first element of the lists inside list2. (I need to output a report of cellOwners for all used cells in my design). When an exact match is found I'll print the cellName and ownerName and jump to the next item in list1 and repeat. Would I use 2 foreach loops?? What would be the most efficient method?

list1 = ("cellA" "cellB" "cellC" "cellD")

list2 = (("cellA" "John_Smith")

                     ("cellB" "Sally_Smith"))

  • Sign in to reply
  • Cancel
  • AaronSymko
    AaronSymko 2 months ago

    The canonical solution would use nested foreach loops; but a simpler, more efficient solution would be to use the "exists" function. Here are some examples:

    list1 = '("cellA" "cellB" "cellC" "cellD")
    
    list2 = '(("cellA" "John_Smith")
    
                         ("cellB" "Sally_Smith"))
    
    ;; Example using nested foreach loops
    foreach(i list1
      foreach(j list2
        when(i == car(j)
          printf("cell %L found with owner %L\n" car(j) cadr(j))
        )
      )
    )
    
    ;; Example using exists
    cellsAndOwners = exists(i list2 !null(member(car(i) list1)))
    foreach(i cellsAndOwners
      printf("cell %L found with owner %L\n" car(i) cadr(i))
    )
    
    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Andrew Beckett
    Andrew Beckett 2 months ago in reply to AaronSymko

    Since the second list is an "assoc" structured list, you could just do:

    foreach(cell list1
      when(found=assoc(cell list2)
        printf("%s %s\n" cell cadr(found))
      )
    )

    If the list of cells and owners is long, you might  be better off putting it into a hash table first:

    cellsAndOwners=makeTable('ownerInfo nil)
    append(cellsAndOwners list2)
    foreach(cell list1
      when(owner=cellsAndOwners[cell]
        printf("%s %s\n" cell owner)
      )
    )

    Andrew

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel

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