Custom sorting question

Devin Asay devin_asay at byu.edu
Thu Apr 20 16:11:46 EDT 2006


Thanks to Brian and Jacque, who supplied the key piece of information  
that the docs don't make clear. The Rev dictionary vaguely says "To  
create a custom sort order, use the each keyword to pass each line or  
item to a custom function. The value returned by the function is used  
as the sort key for that line or item." Brian and Jacque put it much  
more clearly:

On Apr 20, 2006, at 12:43 PM, Brian Yennie wrote:
> See if this helps - the idea is you need your function to return  
> the position you want that item in.

On Apr 20, 2006, at 12:55 PM, J. Landman Gay wrote:

> The way it is now, termOrderSort is returning a number from the  
> item list (such as 259), and the lines will sort numerically using  
> those numbers. What you want is for "259" to be returned as "1" and  
> "26" to be returned as "2", etc. Then the sort works.
...
>
> Using "word 1 of each" sends the actual number in your raw data to  
> the sort function. The sort function gets the item offset of that  
> number from the sort order list. It returns that offset as an  
> integer that will force the data to sort in the proper order; that  
> is, "259" becomes "1", etc.


I only had to make a minor change for it to work properly after their  
suggestions:

> local lSortOrder -- this is the only local you need
>
> on updateList
>   put the rawLessonData of fld "vocablist" into tRawData
>   put "259,26,110,111,272,314,149,250,54" into lSortOrder
>   sort lines of tRawData by termOrderSort(word 1 of each)
>
>   -- do stuff with the sorted list
> end updateList
>
> function termOrderSort tNum
     set the wholeMatches to true ## otherwise '7' matches, '267', etc.
>   return itemoffset(tNum, lSortOrder) -- this returns "1,2,3,4,5,etc"
> end termOrderSort

Thanks for the help!

Devin

Devin Asay
Humanities Technology and Research Support Center
Brigham Young University




More information about the use-livecode mailing list