• 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. how to sort a list alphanumerically with bus names in descending...

Stats

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

how to sort a list alphanumerically with bus names in descending order using skill

RoseRivera
RoseRivera over 7 years ago

I have a list such as :  mylist=list("VDD" "GND" "ddd[0]" "ddd[1]" "ddd[2]" "bb[0]" "bb[1]" "bb[2]")

I try ==>  mylist=sort(mylist 'alphalessp)

the list become ==> ("GND" "VDD" "bb[0]" "bb[1]" "bb[2]" "ddd[0]" "ddd[1]" "ddd[2]")

I want mylist become ("GND" "VDD" "bb[2]" "bb[1]" "bb[0]" "ddd[2]" "ddd[1]" "ddd[0]"). The elements of the list

are sorted alphanumerically, but the bus names are sorted in descending order instead.

Thanks...

  • Cancel
  • DanielDing
    DanielDing over 7 years ago

    maybe something like the following?

    procedure( myLesspCompare( str1 str2 )

      let( (l_chars1 l_chars2)

        l_chars1 = parseString(str1 "[]")

        l_chars2 = parseString(str2 "[]")

        if( length(l_chars1)==1 && length(l_chars2)==1 then

          alphalessp(str1 str2)

        else

          if( length(l_chars1)==1 && length(l_chars2)>1 then

            t

           else

              if( length(l_chars1)>1 && length(l_chars2)==1 then

                nil

             else

                if( car(l_chars1)!=car(l_chars2) then

                  alphalessp(car(l_chars1) car(l_chars2))

                else

                   greaterp(atoi(cadr(l_chars1)) atoi(cadr(l_chars2)))

                );ifelse

              );ifelse

            );ifelse

         );ifelse

     );let

    );procedure

    mylist = sort( mylist 'myLesspCompare)

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • RoseRivera
    RoseRivera over 7 years ago in reply to DanielDing

    Thanks a lot, Daniel. Your solution works for my original list, but let's take another example

    mylist=list("VDD" "GND" "dd_b[0]" "dd_b[1]" "bb_a[0]" "bb_a[1]" "dd_abc" "bb_rst")

    the results after running your code will be ==> ("GND" "VDD" "bb_rst" "dd_abc" "bb_a[1]" "bb_a[0]" "dd_b[1]" "dd_b[0]")

    I want mylist become ("GND" "VDD" "bb_a[1]" "bb_a[0]" "bb_rst" "dd_abc" "dd_b[1]" "dd_b[0]").

    The elements of the list are sorted alphanumerically, and the name with bus quotation are sorted in descending order instead.

    Could you take a look again ...

    Best regards,

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 7 years ago in reply to RoseRivera

    Use this comparison function:

    procedure(MySortCompare(a b)
      let((aSplit bSplit)
        aSplit=car(parseString(a "["))
        bSplit=car(parseString(b "["))
        cond(
          (alphalessp(aSplit bSplit) t)
          (aSplit==bSplit plusp(alphaNumCmp(a b)))
        )
      )
    )

    Essentially if it matches before the [ then it uses alphaNumCmp to do the comparison - which by using plusp is going to give you the result in descending order of the bit that follows the [. For anything else, it's using alphalessp as normal.

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • RoseRivera
    RoseRivera over 7 years ago in reply to Andrew Beckett

    Thanks a lot,Andrew. It works like a charm.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • psill000
    psill000 over 7 years ago in reply to RoseRivera

    Here a bit of plagiarism of Andrews work may also work

    mylist = sort(mylist lambda((a b) minusp(alphaNumCmp(a b))))

    • Cancel
    • Vote Up +1 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 7 years ago in reply to psill000
    psill000 said:
    mylist = sort(mylist lambda((a b) minusp(alphaNumCmp(a b))))

    The complication with the original question was that numerical parts needed to be in descending order, with the alphabetic parts in ascending order. Your (much more compact) solution sorts them both in ascending order - which is of course fine if that's what you want!

    Regards,

    Andrew.

    • 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