• 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. List -> list containing even indexes

Stats

  • Locked Locked
  • Replies 6
  • Subscribers 143
  • Views 5400
  • 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

List -> list containing even indexes

Slawa
Slawa over 15 years ago

 Hello

How it is possible to receive list consisting only from members of initial list with even or odd indexes? For example there is a list containing 7 Cadence database members. How to receive list containing first, third, fifth and seventh members? 

Best regards

Slawa

  • Cancel
Parents
  • skillUser
    skillUser over 15 years ago

    Hi Slawa,

    How about the following?

    myList = '(1 2 3 4 5 6 7 8)
    => (1 2 3 4 5
        6 7 8
       )
    idx = 0
    setof(elem foreach(mapcar item myList evenp(idx++)&&item) elem)
    => (1 3 5 7)
    

    This iterates over the list using foreach mapcar and the result would look like (1 nil 3 nil ...) and then the setof filters this list to remove any 'nil' values.  The input list does not have to be numeric, only the variable idx is required to be numeric. Change the evenp predicate to oddp if the even indexes are needed.

    Regards,

    Lawrence.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • skillUser
    skillUser over 15 years ago

    Hi Slawa,

    How about the following?

    myList = '(1 2 3 4 5 6 7 8)
    => (1 2 3 4 5
        6 7 8
       )
    idx = 0
    setof(elem foreach(mapcar item myList evenp(idx++)&&item) elem)
    => (1 3 5 7)
    

    This iterates over the list using foreach mapcar and the result would look like (1 nil 3 nil ...) and then the setof filters this list to remove any 'nil' values.  The input list does not have to be numeric, only the variable idx is required to be numeric. Change the evenp predicate to oddp if the even indexes are needed.

    Regards,

    Lawrence.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Children
No Data

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