From 6d6e6910838a8a9e1a61d257a180ad2f353228d2 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Wed, 7 Jan 2009 15:58:33 -0600 Subject: [PATCH] Make human-sort behave like sort --- basis/sorting/human/human.factor | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/basis/sorting/human/human.factor b/basis/sorting/human/human.factor index 1c2ba419c7..f338e21887 100644 --- a/basis/sorting/human/human.factor +++ b/basis/sorting/human/human.factor @@ -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 ;