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
11 { "sort-specs" "a sequence of accessors ending with a comparator" }
12 { "<=>" { $link +lt+ } " " { $link +eq+ } " or " { $link +gt+ } }
14 { $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." } ;
18 { "seq" sequence } { "sort-specs" "a sequence of accessors ending with a comparator" }
21 { $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." }
23 "Sort by slot a, then b descending:"
25 "USING: accessors math.order prettyprint sorting.slots ;"
27 "TUPLE: sort-me a b ;"
29 " T{ sort-me f 2 3 } T{ sort-me f 3 2 }"
30 " T{ sort-me f 4 3 } T{ sort-me f 2 1 }"
32 "{ { a>> <=> } { b>> >=< } } sort-by ."
33 "{\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 ARTICLE: "sorting.slots" "Sorting by slots"
38 "The " { $vocab-link "sorting.slots" } " vocabulary can sort tuples by slot in ascending or descending order, using subsequent slots as tie-breakers." $nl
39 "Comparing two objects by a sequence of slots:"
40 { $subsection compare-slots }
41 "Sorting a sequence of tuples by a slot/comparator pairs:"
42 { $subsection sort-by }
43 { $subsection sort-keys-by }
44 { $subsection sort-values-by } ;
46 ABOUT: "sorting.slots"