factor/basis/sorting/human/human.factor

23 lines
742 B
Factor
Raw Normal View History

2008-09-12 16:49:46 -04:00
! Copyright (C) 2008 Doug Coleman, Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
2009-01-07 16:58:33 -05:00
USING: peg.ebnf math.parser kernel assocs sorting fry
math.order sequences ascii splitting.monotonic ;
2008-09-12 16:49:46 -04:00
IN: sorting.human
: find-numbers ( string -- seq )
[EBNF Result = ([0-9]+ => [[ string>number ]] | (!([0-9]) .)+)* EBNF] ;
: human<=> ( obj1 obj2 -- <=> ) [ find-numbers ] bi@ <=> ;
2009-01-07 16:58:33 -05:00
: human>=< ( obj1 obj2 -- >=< ) human<=> invert-comparison ; inline
2009-03-29 22:35:57 -04:00
: human-compare ( obj1 obj2 quot -- <=> ) bi@ human<=> ; inline
2009-01-07 16:58:33 -05:00
: human-sort ( seq -- seq' ) [ human<=> ] sort ;
2009-01-07 16:58:33 -05:00
: human-sort-keys ( seq -- sortedseq )
[ [ first ] human-compare ] sort ;
: human-sort-values ( seq -- sortedseq )
[ [ second ] human-compare ] sort ;