]> gitweb.factorcode.org Git - factor.git/commitdiff
Make human-sort behave like sort
authorDoug Coleman <doug.coleman@gmail.com>
Wed, 7 Jan 2009 21:58:33 +0000 (15:58 -0600)
committerDoug Coleman <doug.coleman@gmail.com>
Wed, 7 Jan 2009 21:58:33 +0000 (15:58 -0600)
basis/sorting/human/human.factor

index 1c2ba419c75e230daf79911ac0b7db11008960f1..f338e218878ae08d57ad01718153a502659aeae2 100644 (file)
@@ -1,10 +1,20 @@
 ! Copyright (C) 2008 Doug Coleman, Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: peg.ebnf math.parser kernel assocs sorting ;
+USING: peg.ebnf math.parser kernel assocs sorting fry
+math.order sequences ascii splitting.monotonic ;
 IN: sorting.human
 
 : find-numbers ( string -- seq )
     [EBNF Result = ([0-9]+ => [[ string>number ]] | (!([0-9]) .)+)* EBNF] ;
 
-: human-sort ( seq -- seq' )
-    [ dup find-numbers ] { } map>assoc sort-values keys ;
+: human-<=> ( obj1 obj2 -- <=> ) [ find-numbers ] bi@ <=> ;
+
+: human-compare ( obj1 obj2 quot -- <=> ) bi@ human-<=> ;
+
+: human-sort ( seq -- seq' ) [ human-<=> ] sort ;
+
+: human-sort-keys ( seq -- sortedseq )
+    [ [ first ] human-compare ] sort ;
+
+: human-sort-values ( seq -- sortedseq )
+    [ [ second ] human-compare ] sort ;