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 8:35

From: "Terry Brownell"
> Here's a exercise... > > Sort the following read/lines into N: from shortest length? line to
longest...
> N:[] > > one two three "four five six" ; length? = 4 > one two "three four" ; length? = 3 > one two three four five "six seven" ; length? = 6 > one two three four five six "seven eight" ; length? = 7 > one "two three four five" ; length? = 2 > > Where the string counts as 1. > > So you end up with ... > > N: [ > one "two three four five" > one two "three four" > one two three "four five six" > one two three four five "six seven" > one two three four five six "seven eight" > ]
Well, I feel like I'm cheating, but ... input.txt contains the following text: one two three "four five six" one two "three four" one two three four five "six seven" one two three four five six "seven eight" one "two three four five" Then: n: sort read/lines %/c/path/to/input.txt The result: foreach o n [print o] What I learned from this exercise was that sort in this context used the subseries length. I have to admit to being a bit surprised, but maybe I should not have been. --Scott Jones