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

[REBOL] Re: Simple sorting

From: carl:cybercraft at: 26-Sep-2002 12:42

On 26-Sep-02, Sean Johnson wrote:
> Content-Type: text/plain; > charset="iso-8859-1" > Content-Transfer-Encoding: quoted-printable > > Hi all, > > Been off the list for a while because I just couldn't keep up with > the = volume of this great living list! Quickie question: > How do I get the code, listing: sort read %., to sort alphabetically > by = directories first then by filenames? So, the result looks like > this: >>> sort read %. > == [%dir1/ %dir2/ %dir3/ %file1 %file2 %file3] > > I know I'm missing something easy here...maybe a sort option? > > Regards, > > Sean C. Johnson
Sort has a compare refinement that allows you to use a function to make a comparison, the idea being to return true or false depending on a comparison of two values. (I think - I only used it for the first time yesterday:) For instance, this sorts on strings from the second character onwards...
>> blk: ["xccc" "yaaa" "zbbb"]
== ["xccc" "yaaa" "zbbb"]
>> sort/compare blk func [a b][(second a) < second b]
== ["yaaa" "zbbb" "xccc"] So, expand on that to sort your directory. (My rushed attempt didn't work, so I won't inflict it on you;) Note, if you seperate your function, use... sort/compare blk :my-function Note the colon. -- Carl Read