• 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 5399
  • 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
  • eDave
    eDave over 15 years ago

    mapcar(lambda((items) list(car(items) caddr(items) nth(4 items) nth(6 items))) myList)

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Slawa
    Slawa over 15 years ago

     Ок and if quantity of members of list equally N and me it is necessary to receive list containing every second?

     

    Best regard

    Slawa 

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • berndf
    berndf over 15 years ago

    My solution, don't know if this is what your exactly looking for.

     Bernd

     

    let( ( myList listLegth evenIndexList oddIndexList )

    myList = list( "one" "two" "three" "four" "five" "six" "seven" )

    listLegth = length( myList )

    for( n 1 listLegth
      cond(
        ( evenp( n )
          evenIndexList = nconc( evenIndexList list( nthelem( n myList ) ) )
        )
        ( oddp( n )
          oddIndexList = nconc( oddIndexList list( nthelem( n myList ) ) )
        )
      )
    )

    printf( "evenIndexList: %L\n" evenIndexList )
    printf( "oddIndexList: %L\n" oddIndexList )

    )

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Slawa
    Slawa over 15 years ago

     Many thanks Berndf it that is necessary.

     

    Best regards

    Slawa 

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • 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
  • Slawa
    Slawa over 15 years ago

     Thanks Lawrence.
    This variant too approaches also it a bit easier offered above.

     

    Best regards

    Slawa 

    • 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