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

[REBOL] Re: Sorting

From: gjones05:mail:orion at: 17-May-2001 11:39

From: "Terry Brownell"
<snip> > try this one... > > two three "four five six" > five six "three four" > one two three four five "six seven" > two three four five six seven "eight nine ten" > nine "ten eleven twelve" > > again, sorted based on parsed length? and then alpha (but not
necessary)
> also, the length? of the str is irrelevant. > so.. > > N: [ > nine "ten eleven twelve" > five six "three four" > two three "four five six" > one two three four five "six seven" > two three four five six seven "eight nine ten" > ]
Well, this one certainly helped to point out why the other was only accidentally correct. Now you've gone and forced me to do it the right way. Grumble, grumble ;-) input.txt contains: two three "four five six" five six "three four" one two three four five "six seven" two three four five six seven "eight nine ten" nine "ten eleven twelve" Then the code...: sort-check: func [a b] [ either ((length? to-block a) = (length? to-block b)) [ a < b ][ ((length? to-block a) < (length? to-block b)) ] ] n: sort/compare read/lines %/path/to/input.txt :sort-check foreach i n [print i] Yields: nine "ten eleven twelve" five six "three four" two three "four five six" one two three four five "six seven" two three four five six seven "eight nine ten" Next example, please?! ;-) (Actually I had been trying to figure out more complicated sort/compare's before, now I think I've got it!) --Scott Jones