Home > Community > Forums > Custom IC SKILL > sort lists in SKILL/OCEAN

Email

* Required Fields

Recipients email * (separate multiple addresses with commas)

Your name *

Your email *

Message *

Contact Us

* Required Fields
First Name *

Last Name *

Email *

Company / Institution *

Comments: *

 sort lists in SKILL/OCEAN 

Last post Wed, Dec 5 2012 2:49 AM by Andrew Beckett. 5 replies.
Started by mbchang 04 Dec 2012 01:36 PM. Topic has 5 replies and 1410 views
Page 1 of 1 (6 items)
Sort Posts:
  • Tue, Dec 4 2012 1:36 PM

    • mbchang
    • Not Ranked
    • Joined on Thu, Sep 6 2012
    • Posts 9
    • Points 150
    sort lists in SKILL/OCEAN Reply

     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]"   )

    )

    • Post Points: 20
  • Tue, Dec 4 2012 1:44 PM

    Re: sort lists in SKILL/OCEAN Reply

    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.

    • Post Points: 20
  • Tue, Dec 4 2012 2:32 PM

    • mbchang
    • Not Ranked
    • Joined on Thu, Sep 6 2012
    • Posts 9
    • Points 150
    Re: sort lists in SKILL/OCEAN Reply

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

     

    Thanks for the tips.

     

    Jerry

    • Post Points: 20
  • Tue, Dec 4 2012 3:35 PM

    • skillUser
    • Top 10 Contributor
    • Joined on Fri, Sep 19 2008
    • Austin, TX
    • Posts 2,569
    • Points 15,600
    Re: sort lists in SKILL/OCEAN Reply

     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

    • Post Points: 20
  • Wed, Dec 5 2012 2:00 AM

    • berndfi
    • Top 100 Contributor
    • Joined on Tue, Sep 11 2012
    • Neubiberg, Bavaria
    • Posts 67
    • Points 1,255
    Re: sort lists in SKILL/OCEAN Reply

     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
    • Post Points: 20
  • Wed, Dec 5 2012 2:49 AM

    Re: sort lists in SKILL/OCEAN Reply

    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.

    • Post Points: 5
Page 1 of 1 (6 items)
Sort Posts:
Started by mbchang at 04 Dec 2012 01:36 PM. Topic has 5 replies.