1 ! Copyright (C) 2009 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: help.markup help.syntax kernel quotations math.order
9 { "sort-specs" "a sequence of accessors ending with a comparator" }
10 { "<=>" { $link +lt+ } " " { $link +eq+ } " or " { $link +gt+ } }
12 { $description "Compares two objects using a chain of intrinsic linear orders such that if two objects are " { $link +eq+ } ", then the next comparator is tried. The comparators are slot-name/comparator pairs." } ;
16 { "seq" sequence } { "sort-specs" "a sequence of accessors ending with a comparator" }
19 { $description "Sorts a sequence of tuples by the sort-specs in " { $snippet "sort-spec" } ". A sort-spec is a sequence of slot accessors ending in a comparator." }
21 "Sort by slot c, then b descending:"
23 "USING: accessors math.order prettyprint sorting.slots ;"
25 "TUPLE: sort-me a b ;"
27 " T{ sort-me f 2 3 } T{ sort-me f 3 2 }"
28 " T{ sort-me f 4 3 } T{ sort-me f 2 1 }"
30 "{ { a>> <=> } { b>> >=< } } sort-by-slots ."
31 "{\n T{ sort-me { a 2 } { b 3 } }\n T{ sort-me { a 2 } { b 1 } }\n T{ sort-me { a 3 } { b 2 } }\n T{ sort-me { a 4 } { b 3 } }\n}"
37 { "accessor-seqs" "a sequence of sequences of tuple accessors" }
40 { $description "Splits a sequence of tuples into a sequence of slices of tuples that have the same values in all slots in the accessor sequence. This word is only useful for splitting a sorted sequence, but is more efficient than partitioning in such a case." } ;
42 ARTICLE: "sorting.slots" "Sorting by slots"
43 "The " { $vocab-link "sorting.slots" } " vocabulary can sort tuples by slot in ascending or descending order, using subsequent slots as tie-breakers." $nl
44 "Comparing two objects by a sequence of slots:"
45 { $subsection compare-slots }
46 "Sorting a sequence by a sequence of slots:"
47 { $subsection sort-by-slots } ;
49 ABOUT: "sorting.slots"