]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/uuid/uuid.factor
use radix literals
[factor.git] / basis / uuid / uuid.factor
index 2fd6ffdaecb41d86008476796a01412f280ec2f4..3bbc930896b2de58834fd5c52f781bdc35639c20 100644 (file)
@@ -1,11 +1,9 @@
 ! Copyright (C) 2008 John Benediktsson
 ! See http://factorcode.org/license.txt for BSD license
-
-USING: byte-arrays checksums checksums.md5 checksums.sha1 
-kernel math math.parser math.ranges random unicode.case 
-sequences strings system io.binary ;
-
-IN: uuid 
+USING: byte-arrays calendar checksums checksums.md5
+checksums.sha io.binary kernel math math.parser math.ranges
+random sequences strings system unicode.case ;
+IN: uuid
 
 <PRIVATE
 
@@ -13,16 +11,16 @@ IN: uuid
     ! 0x01b21dd213814000L is the number of 100-ns intervals
     ! between the UUID epoch 1582-10-15 00:00:00 and the 
     ! Unix epoch 1970-01-01 00:00:00.
-    micros 10 * HEX: 01b21dd213814000 +
-    [ -48 shift HEX: 0fff bitand ] 
-    [ -32 shift HEX: ffff bitand ]
-    [ HEX: ffffffff bitand ]
+    gmt timestamp>micros 10 * 0x01b21dd213814000 +
+    [ -48 shift 0x0fff bitand ] 
+    [ -32 shift 0xffff bitand ]
+    [ 0xffffffff bitand ]
     tri ;
 
 : (hardware) ( -- address ) 
     ! Choose a random 48-bit number with eighth bit 
     ! set to 1 (as recommended in RFC 4122)
-    48 random-bits HEX: 010000000000 bitor ;
+    48 random-bits 0x010000000000 bitor ;
 
 : (clock) ( -- clockseq ) 
     ! Choose a random 14-bit number
@@ -37,9 +35,9 @@ IN: uuid
 
 : (version) ( n version -- n' )
     [
-        HEX: c000 48 shift bitnot bitand 
-        HEX: 8000 48 shift bitor 
-        HEX: f000 64 shift bitnot bitand
+        0xc000 48 shift bitnot bitand 
+        0x8000 48 shift bitor 
+        0xf000 64 shift bitnot bitand
     ] dip 76 shift bitor ;
 
 : uuid>string ( n -- string )
@@ -50,7 +48,7 @@ IN: uuid
     [ CHAR: - 8 ] dip insert-nth ;
  
 : string>uuid ( string -- n )
-    [ CHAR: - = not ] filter 16 base> ;
+    [ CHAR: - = not ] filter hex> ;
 
 PRIVATE>