• 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. sort lists in SKILL/OCEAN

Stats

  • Locked Locked
  • Replies 5
  • Subscribers 144
  • Views 7700
  • 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

sort lists in SKILL/OCEAN

mbchang
mbchang over 12 years ago

 I have a list which includes several lists inside. Is there any way that I can sort the lists alphabetly based on the first part of each list (signal name)?

 

Thanks!

list( 

list("V105A_ymax_v9overshoot_1"   float(0.9975)  float(1.1025) "[V]"   )
list("V105A_riseTime_v9ramptime_1"   float(300u)  float(2m) "[s]"   )
list("V5A_DS3_delay10_v5a_on_1"   float(0.0)  float(500u) "[s]"   )
list("V33A_DSW_peakToPeak_v4vripple_1"   float(0.0)  float(50.0m) "[V]"   )
list("V5A_DS3_ymin_v2pgoodincr_1"   float(4.65)  float(4.85) "[V]"   )
list("DPWROK_delay90_pwrok_delay_1"   float(10m)  float(15m) "[s]"   )
list("V33A_DSW_average_v4voutavg_1"   float(3.135)  float(3.465) "[V]"   )
list("V105A_ymin_v9pgoodincr_1"   float(0.965)  float(1.03) "[V]"   )

)

  • Cancel
  • Andrew Beckett
    Andrew Beckett over 12 years ago

    The simplest way to do this is to use sortcar() with your example. Assuming myList contains the list:

    myList=sortcar(myList 'alphalessp)

    That outputs this:

     (("DPWROK_delay90_pwrok_delay_1" 0.01 0.015 "[s]")
        ("V105A_riseTime_v9ramptime_1" 0.0003 0.002 "[s]")
        ("V105A_ymax_v9overshoot_1" 0.9975 1.1025 "[V]")
        ("V105A_ymin_v9pgoodincr_1" 0.965 1.03 "[V]")
        ("V33A_DSW_average_v4voutavg_1" 3.135 3.465 "[V]")
        ("V33A_DSW_peakToPeak_v4vripple_1" 0.0 0.05 "[V]")
        ("V5A_DS3_delay10_v5a_on_1" 0.0 0.0005 "[s]")
        ("V5A_DS3_ymin_v2pgoodincr_1" 4.65 4.85 "[V]")
    )

    In the absence of sortcar, you could do:

    myList=sort(myList lambda((a b) alphalessp(car(a) car(b))))

    In other words, the second argument to sort is a function that compares two values and returns t if the first is "less" than the second. You can then do whatever comparison you like - here I'm using alphalessp on the car of each entry, which is your signal name here. I could equally well sort on the second entry in each list (the numbers) by doing:

    myList=sort(myList lambda((a b) cadr(a)<cadr(b)))

    And so on.

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • mbchang
    mbchang over 12 years ago

     never mind. I think I can build the list twice.

     

    Thanks for the tips.

     

    Jerry

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • skillUser
    skillUser over 12 years ago

     Hi Jerry,

    To respond to your last question (that's now disappeared) - how about sorting everything in the list except for the first element?  In that case you could sort the cdr of the list, that is to say, everything in the 'tail' of the list, after taking the first item (the 'head') away.  Beware that "sort" is a destructive list operator, so you must save the return result of the sort function since it modifies the list in place.

    Hopefully this helps you?

    Regards,

    Lawrence

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • berndfi
    berndfi over 12 years ago

     This could probalby do it.

    Andrew wasn't the intial code from you? Can't remeber.

    /****f* /listProcessing/LPindexSort
    * NAME
    *   LPindexSort
    *
    * SYNOPSIS
    *   LPindexSort( x_index0 l_listOfList u_comparefn )
    *
    * DESCRIPTION
    *   This function sorts a list of lists acoording to the elements given by a
    *   index for the sublist.
    *  
    * ARGUMENTS
    *   x_index0        - Index for the sublist element which sould be used for the
    *                     sort.
    *   l_listOfList    - A list of lists.
    *   u_comparefn     - The compare function applied for the sort.
    *
    * RETURN VALUE
    *   l_result
    *
    * EXAMPLE
    *   l_listA = list(
    *               list( "Kiwi" "Banana" "Grape" )
    *               list( "Apple" "Grape" "Banana" )
    *               list( "Banana" "Kiwi" "Apple" )
    *               list( "Apple" "Banana" "Kiwi" )
    *               )
    *   LPindexSort( 1 l_listA 'alphalessp )
    *   => (("Kiwi" "Banana" "Grape")
    *          ("Apple" "Banana" "Kiwi")
    *          ("Apple" "Grape" "Banana")
    *          ("Banana" "Kiwi" "Apple"))
    *
    *   l_listB = list(
    *               list( 6 3.0 2 )
    *               list( 1.0 4 5 )
    *               list( 4.0 2 6 )
    *               list( 1 2 7.0 )
    *               )
    *   LPindexSort( 1 l_listB 'lessp )
    *   => ((4.0 2 6)
    *          (1 2 7.0)
    *          (6 3.0 2)
    *          (1.0 4 5))
    *    
    * SOURCE
    */

    procedure( LPindexSort( x_index0 l_listOfList u_comparefn )
        let( ( l_sortedListOfList )
        
        l_sortedListOfList = sort(
            l_listOfList
        lambda( ( a b )
            while( and(
                    nth( x_index0 a ) nth(  x_index0 b )
                    equal( nth( x_index0 a ) nth(  x_index0 b ) ) )
                    setq( a cdr( a ) )
                    setq( b cdr( b ) ) )
                    and( nth( x_index0 a ) nth(  x_index0 b )
                    apply( u_comparefn list( nth( x_index0 a ) nth(  x_index0 b ) ) ) )
            )  
        )  
    ) ;; close let
    ) ;; close procedure
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 12 years ago

    I agree (the code wasn't from me though - I don't believe in having the type of variables encoded in the names as it makes them hard to read, so it wasn't my code).

    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