]> gitweb.factorcode.org Git - factor.git/blob - basis/sorting/human/human.factor
fix human sort -- wrap all elements so that integers dont get compared against string...
[factor.git] / basis / sorting / human / human.factor
1 ! Copyright (C) 2008 Doug Coleman, Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: math.parser peg.ebnf sorting.functor ;
4 IN: sorting.human
5
6 : find-numbers ( string -- seq )
7     [EBNF Result = ([0-9]+ => [[ string>number ]] | (!([0-9]) .)+)* EBNF] ;
8
9 ! For comparing integers or sequences
10 TUPLE: hybrid obj ;
11
12 M: hybrid <=>
13     [ obj>> ] bi@
14     2dup [ integer? ] bi@ xor [
15         drop integer? [ +lt+ ] [ +gt+ ] if
16     ] [
17         <=>
18     ] if ;
19
20 << "human" [ find-numbers [ hybrid boa ] map ] define-sorting >>