]> gitweb.factorcode.org Git - factor.git/commitdiff
use functors to define human-sort
authorDoug Coleman <erg@jobim.local>
Fri, 3 Apr 2009 22:28:31 +0000 (17:28 -0500)
committerDoug Coleman <erg@jobim.local>
Fri, 3 Apr 2009 22:28:31 +0000 (17:28 -0500)
basis/sorting/human/human-docs.factor
basis/sorting/human/human.factor

index 5952b3e3f9fb21d0c1edd205416d99c8aea83904..606eef670a031cfd79cbe1b279e44c9031247f91 100644 (file)
@@ -35,7 +35,7 @@ HELP: human-compare
 HELP: human-sort
 { $values
      { "seq" sequence }
-     { "seq'" sequence }
+     { "sortedseq" sequence }
 }
 { $description "Sorts a sequence of objects by comparing the magnitude of any integers in the input string using the <=> word." } ;
 
index c07ed8758ba0e1d9cf947d502a34ff3bc8ad3fc0..b3dae45a9b87d26fd94d46ed04e9439be96a1ebd 100644 (file)
@@ -1,22 +1,9 @@
 ! Copyright (C) 2008 Doug Coleman, Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: peg.ebnf math.parser kernel assocs sorting fry
-math.order sequences ascii splitting.monotonic ;
+USING: math.parser peg.ebnf sorting.functor ;
 IN: sorting.human
 
 : find-numbers ( string -- seq )
     [EBNF Result = ([0-9]+ => [[ string>number ]] | (!([0-9]) .)+)* EBNF] ;
 
-: human<=> ( obj1 obj2 -- <=> ) [ find-numbers ] bi@ <=> ;
-
-: human>=< ( obj1 obj2 -- >=< ) human<=> invert-comparison ; inline
-
-: human-compare ( obj1 obj2 quot -- <=> ) bi@ human<=> ; inline
-
-: human-sort ( seq -- seq' ) [ human<=> ] sort ;
-
-: human-sort-keys ( seq -- sortedseq )
-    [ [ first ] human-compare ] sort ;
-
-: human-sort-values ( seq -- sortedseq )
-    [ [ second ] human-compare ] sort ;
+<< "human" [ find-numbers ] define-sorting >>