Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Sort in REBOL

 [1/4] from: carl:s:rebol at: 7-Sep-2002 13:45


Noticed the thread on SORT, but I don't have time to read it all. A few notes: 1) SORT in recent versions of REBOL is much more reliable. It is also quite fast, but that depends on what you're sorting and the function you use for comparison. We use it all the time. 2) If you want a stable sort, return 1, -1, and 0 from a sort subfunction, rather than true and false. sort/compare data func [a b] [ if a < b [return 1] if a > b [return -1] 0 ] 3) The /ALL refinement allows you to sort more complex data, for example, by data fields within blocks: data: [ ["name" 123] ["fred" 345] ] sort/compare/all data func [a b] [a/2 < b/2] Perhaps you already know all this... but, I figured, what the heck... -Carl

 [2/4] from: jason::cunliffe::verizon::net at: 7-Sep-2002 23:55


> 3) The /ALL refinement allows you to sort more complex data, > for example, by data fields within blocks: > > data: [ ["name" 123] ["fred" 345] ] > sort/compare/all data func [a b] [a/2 < b/2] > > Perhaps you already know all this... but, I figured, what the > heck...
I did not and yes that's very cool. Thanks!! ./Jason

 [3/4] from: rotenca:telvia:it at: 8-Sep-2002 15:05


Hi
> > 3) The /ALL refinement allows you to sort more complex data, > > for example, by data fields within blocks:
<<quoted lines omitted: 5>>
> > heck... > I did not and yes that's very cool.
Or there is something i do not understand, or the Carl example is wrong (!). I do not see here any difference in using ALL. Like changes doc of Core 2.5 explains, ALL must be used with SKIP: /all Used in combination with the /skip refinement. [NEW] By default only a single field in a record is used for comparison. If the /all refinement is used then all fields in a record are used for comparison. --- Ciao Romano

 [4/4] from: carl:s:rebol at: 10-Sep-2002 10:02


Yes, sorry, I oversimplified it for the email... Normally the data would be such that you would use a /skip/all combination. You are correct. Here's a better example: data: [ abc ["name" 123] def ["fred" 345] ] sort/skip/compare/all data 2 func [a b] [a/2/1 < b/2/1] At 9/8/02 03:05 PM +0200, you wrote:

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted