2009-01-08 17:32:26 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								! Copyright (C) 2009 Doug Coleman. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								! See http://factorcode.org/license.txt for BSD license. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								USING:  help.markup  help.syntax  kernel  math.order  quotations 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								sequences strings ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								IN:  sorting.human 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								HELP:  find-numbers 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ $values
							 
						 
					
						
							
								
									
										
										
										
											2010-09-21 12:17:39 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								     { "sequence"  sequence  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     { "sequence'"  sequence  }
							 
						 
					
						
							
								
									
										
										
										
											2009-01-08 17:32:26 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ $description "Splits a string on numbers and returns a sequence of sequences and integers."  } ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-01-26 01:32:02 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								HELP:  human<=> 
							 
						 
					
						
							
								
									
										
										
										
											2009-01-08 17:32:26 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								{ $values
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     { "obj1"  object  } { "obj2"  object  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     { "<=>"  "an ordering specifier"  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ $description "Compares two objects after converting numbers in the string into integers."  } ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-01-26 01:32:02 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								HELP:  human>=< 
							 
						 
					
						
							
								
									
										
										
										
											2009-01-08 17:32:26 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								{ $values
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     { "obj1"  object  } { "obj2"  object  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     { ">=<"  "an ordering specifier"  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								}
							 
						 
					
						
							
								
									
										
										
										
											2009-01-26 01:32:02 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ $description "Compares two objects using the "  { $link human<=> } " word and inverts the result."  } ;
 
							 
						 
					
						
							
								
									
										
										
										
											2009-01-08 17:32:26 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-01-27 16:38:01 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								ARTICLE: "sorting.human"  "Human-friendly sorting" 
							 
						 
					
						
							
								
									
										
										
										
											2009-01-08 17:32:26 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								"The "  { $vocab-link "sorting.human"  } " vocabulary sorts by numbers as a human would -- by comparing their magnitudes -- rather than in a lexicographic way. For example, sorting a1, a10, a03, a2 with human sort returns a1, a2, a03, a10, while sorting with natural sort returns a03, a1, a10, a2."  $nl
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								"Comparing two objects:" 
							 
						 
					
						
							
								
									
										
										
										
											2009-10-01 15:56:36 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ $subsections
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    human<=>
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    human>=<
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								}
							 
						 
					
						
							
								
									
										
										
										
											2009-01-08 17:32:26 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								"Splitting a string into substrings and integers:" 
							 
						 
					
						
							
								
									
										
										
										
											2009-10-01 15:56:36 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ $subsections find-numbers } ;
 
							 
						 
					
						
							
								
									
										
										
										
											2009-01-08 17:32:26 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								ABOUT: "sorting.human"