• 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. unexpected sort behavior

Stats

  • Locked Locked
  • Replies 2
  • Subscribers 143
  • Views 3476
  • 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

unexpected sort behavior

amac
amac over 1 year ago

Hello, have you ever experienced a sort function that "eats" part of a list?

m=list(list("a" "MM") list("p" "PP" ))
sort(m lambda((a b) alphalessp(cadr(b) cadr(a))))

If executed from CIW it correctly produces:

m
(("a" "MM")
    ("p" "PP")
)

If executed within a .il file it gives:

m
(("a" "MM"))

What is happening?

  • Cancel
  • AurelBuche
    AurelBuche over 1 year ago

    Hi,

    sort is a destructive function.

    It actually modifies the pointers inside your list, you should always be careful while using it : 

    It's OK, if you sort a list that is generated on the fly
    (sort (geGetEditCellView)->instances (lambda (i0 i1) (alphalessp i0->name i1->name))))

    Otherwise, you have two solutions : 

    1. Re-assign the sorted list : 
    m = list(list("a" "MM") list("p" "PP" ))
    m = sort(m lambda((a b) alphalessp(cadr(b) cadr(a))))

    2. Copy the list before sort : 
    m = list(list("a" "MM") list("p" "PP" ))
    sort(copy(m) lambda((a b) alphalessp(cadr(b) cadr(a))))


    Cheers

    Aurélien

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • amac
    amac over 1 year ago in reply to AurelBuche

    Indeed assigning the result to m itself solves the issue.

    Thanks a lot!

    • 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