How to sort this rebol domain names block on date?
I want to sort this block on date column:
["domain1.com" 18-Jan-2011 #"^/"
"domain2.com" 20-Aug-2011 #"^/"
"domain3.com" 23-Dec-2011 #"^/"
"domain4.com" 22-Sep-2011 #"^/"]
I can't see how to really do so with sort/skip function explai开发者_Go百科ned here, it's not crystal clear for me: http://www.rebol.com/docs/words/wsort.html
You've got groups of three fields, and you want to sort on field 2?
This should do it:
data: [
"domain1.com" 18-Jan-2011 #"^/"
"domain2.com" 20-Aug-2011 #"^/"
"domain3.com" 23-Dec-2011 #"^/"
"domain4.com" 22-Sep-2011 #"^/"
]
sort/skip/compare data 3 2
You want the /all
refinement used with a comparator function. That gets it to pass the subseries (which is as long as the skip length) to the comparator as the "record", instead of just passing the first element of that series.
>> sort/skip/compare/all ["domain1.com" 18-Jan-2011 #"^/"
"domain2.com" 20-Aug-2011 #"^/"
"domain3.com" 23-Dec-2011 #"^/"
"domain4.com" 22-Sep-2011 #"^/"] 3 func [a b] [
(second a) < (second b)
]
== ["domain1.com" 18-Jan-2011 #"^/"
"domain2.com" 20-Aug-2011 #"^/"
"domain4.com" 22-Sep-2011 #"^/"
"domain3.com" 23-Dec-2011 #"^/]
It works in Rebol 2 but in the version of Rebol 3 I'm currently running, it's not working. That's a bug.
精彩评论