]> gitweb.factorcode.org Git - factor.git/commitdiff
simplify "version<=>"
authorMaximilian Lupke <simply.malu@googlemail.com>
Mon, 22 Feb 2010 20:51:29 +0000 (21:51 +0100)
committerMaximilian Lupke <simply.malu@googlemail.com>
Tue, 23 Feb 2010 12:25:34 +0000 (13:25 +0100)
extra/semantic-versioning/semantic-versioning.factor

index ab7478ac948471e35b68c246be37f887ff8950ee..86973688cb8865b47068a536f7b8b0892622cf98 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2010 Maximilian Lupke.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: arrays ascii combinators kernel math.order math.parser
-sequences splitting ;
+USING: arrays ascii kernel math.order math.parser sequences splitting
+;
 IN: semantic-versioning
 
 : split-version ( string -- array )
@@ -10,16 +10,10 @@ IN: semantic-versioning
     [ drop [ string>number ] tri@ 3array ]
     if ;
 
-! okay, not beautiful
 : version<=> ( version1 version2 -- <=> )
-    [ split-version ] bi@
-    {
-        { [ [ unclip ] bi@ swapd <=> dup +eq+ = not ] [ 2nip ] }
-        { [ drop [ unclip ] bi@ swapd <=> dup +eq+ = not ] [ 2nip ] }
-        { [ drop [ unclip ] bi@ swapd <=> dup +eq+ = not ] [ 2nip ] }
-        { [ drop 2dup [ length ] bi@ >=< dup +eq+ = not ] [ 2nip ] }
-        [ drop [ first ] bi@ <=> ]
-    } cond ;
+    [ split-version ] bi@ drop-prefix
+    2dup [ length 0 = ] either?
+    [ [ length ] bi@ >=< ] [ [ first ] bi@ <=> ] if ;
 
 : version< ( version1 version2 -- ? )
     version<=> +lt+ = ;