| 
									
										
										
										
											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-05-26 13:01:28 -04:00
										 |  |  | USING: accessors kernel math math.order math.parser peg.ebnf | 
					
						
							|  |  |  | sequences sorting.functor ;
 | 
					
						
							| 
									
										
										
										
											2008-09-12 16:49:46 -04:00
										 |  |  | IN: sorting.human | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : find-numbers ( string -- seq )
 | 
					
						
							|  |  |  |     [EBNF Result = ([0-9]+ => [[ string>number ]] | (!([0-9]) .)+)* EBNF] ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-26 11:05:55 -04:00
										 |  |  | ! For comparing integers or sequences | 
					
						
							|  |  |  | TUPLE: hybrid obj ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | M: hybrid <=> | 
					
						
							|  |  |  |     [ obj>> ] bi@
 | 
					
						
							|  |  |  |     2dup [ integer? ] bi@ xor [ | 
					
						
							|  |  |  |         drop integer? [ +lt+ ] [ +gt+ ] if
 | 
					
						
							|  |  |  |     ] [ | 
					
						
							|  |  |  |         <=> | 
					
						
							|  |  |  |     ] if ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | << "human" [ find-numbers [ hybrid boa ] map ] define-sorting >> |