• 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. Is there a command to return the index of an element if...

Stats

  • Locked Locked
  • Replies 3
  • Subscribers 149
  • Views 19583
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Is there a command to return the index of an element if it exists in a list or array?

CADcasualty
CADcasualty over 5 years ago

Hopefully a quickie (and I did search the documentation beforehand). I'm looking for a command that will take an array (preferred) or list and an object return the index of the object if it exists in the array or list. I know I can use e.g. the member function and do a subtraction between the lengths of the original and member lists, but I was hoping there was a native command that just did what I was after. Ideally the command would look like:

myList = list(1 2 "ab" "ef" 1.234)  

some_function("ef" myList)  would return 3  (i.e. nth(3 myList) yields "ef")

  • Cancel
  • AaronSymko
    AaronSymko over 5 years ago

    I believe what you want is the "lindex" function:

    The lindex function returns the index number of the given element in a list.
    lindex(l_list g_element) returns nil if the given element is not present in the list.

    Examples:
    lindex('(1 2 3 4) 2) => 2
    lindex('(1 6 4 5) 4) => 3
    lindex('(1 4 6 7) 3) => nil

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 5 years ago in reply to AaronSymko

    AaronSymko beat me to it ;-)

    Note that the index is in a form that is suitable for use by nthelem not nth (so it's 1-indexed rather than 0-indexed - i.e. US floor numbering rather than European!). That said, any time you find yourself using nth/nthelem, you should always ask "should I be doing this?" (see my Writing Good SKILL Code video)

    I don't believe there's an equivalent function for arrays/vectors. Probably worth requesting an aindex or vindex function...

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • CADcasualty
    CADcasualty over 5 years ago

    So what took you guys so long ;-) ...

    (and thanks!)

    • Cancel
    • Vote Up 0 Vote Down
    • 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