• 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 function to get first several elements of a list...

Stats

  • Locked Locked
  • Replies 1
  • Subscribers 143
  • Views 17107
  • 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 function to get first several elements of a list?

richardyuan
richardyuan over 11 years ago

I need to get part of a list. Is there a function in skill? It's better return a list.

I tried some coding, but failed:

a = list((0:0) (1:1) (2:2) (3:3) (4:2) (5:0))

b = nthcdr(3 a) 

c = remove(b a)

As I suppose, c should be a list of ((0:0) (1:1) (2:2)). But actually c is equal to a. 

What's wrong?

 

  • Cancel
Parents
  • Andrew Beckett
    Andrew Beckett over 11 years ago

    You can do this destructively (which means it is quite efficient) using the following:

    rplacd(nthcdr(2 a) nil)

    a =>  ((0 0) (1 1) (2 2))

    If you wanted a non-destructive list range function, you could implement it like this:

    procedure(CCFlistRange(lst start end)
      let((tail)
        tail=copy(nthcdr(start lst))
        rplacd(nthcdr(end-start tail) nil)
        tail
      )
    )

    Whether this would be more efficient than doing something like:

    procedure(CCFlistRange(lst start end)
      let(((count 0))
        setof(elem lst prog1(count>=start && count<=end count++))
      )
    )

    Would need some profiling and testing with various list sizes.

    Regards,

    Andrew.

     

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • Andrew Beckett
    Andrew Beckett over 11 years ago

    You can do this destructively (which means it is quite efficient) using the following:

    rplacd(nthcdr(2 a) nil)

    a =>  ((0 0) (1 1) (2 2))

    If you wanted a non-destructive list range function, you could implement it like this:

    procedure(CCFlistRange(lst start end)
      let((tail)
        tail=copy(nthcdr(start lst))
        rplacd(nthcdr(end-start tail) nil)
        tail
      )
    )

    Whether this would be more efficient than doing something like:

    procedure(CCFlistRange(lst start end)
      let(((count 0))
        setof(elem lst prog1(count>=start && count<=end count++))
      )
    )

    Would need some profiling and testing with various list sizes.

    Regards,

    Andrew.

     

    • 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