uuid: Universally Unique Identifiers
The uuid library provides functions for generating UUIDs (universally unique identifiers), implemented in pure Racket.
Specifically, uuid-symbol and uuid-string generate version 4 UUIDs based on crypto-random-bytes, which obtains cryptographic-quality randomness from the operating system.
procedure
procedure
Symbols are often an ideal way to represent UUIDs in Racket, since they are always immutable and can be compared cheaply with eq?. On the other hand, strings are often needed to interoperate with external systems like databases, so in some circumstances uuid-string may be more convienient. To consistently convert UUID strings to symbols, use uuid-string->symbol.
> (uuid-symbol) 'b3e34db7-edd9-4f79-aab5-8f3f4cb3c5c3
> (uuid-string) "cc30deeb-ae56-432d-ae2c-b3f29859b94a"
procedure
(strict-uuid-string? v) → boolean?
v : any/c
#px"^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
> (strict-uuid-string? "f81d4fae-7dec-11d0-a765-00a0c91e6bf6") #t
> (strict-uuid-string? "F81D4FAE-7DEC-11D0-A765-00A0C91E6BF6") #f
> (strict-uuid-string? "f81D4fAE-7dec-11D0-A765-00a0C91e6bf6") #f
procedure
(uuid-symbol? v) → boolean?
v : any/c
(λ (v) (and (symbol? v) (strict-uuid-string? (symbol->string v))))
> (uuid-symbol? 'f81d4fae-7dec-11d0-a765-00a0c91e6bf6) #t
> (uuid-symbol? 'F81D4FAE-7DEC-11D0-A765-00A0C91E6BF6) #f
> (uuid-symbol? 'f81D4fAE-7dec-11D0-A765-00a0C91e6bf6) #f
procedure
(uuid-string? v) → boolean?
v : any/c
> (uuid-string? "f81d4fae-7dec-11d0-a765-00a0c91e6bf6") #t
> (uuid-string? "F81D4FAE-7DEC-11D0-A765-00A0C91E6BF6") #t
> (uuid-string? "f81D4fAE-7dec-11D0-A765-00a0C91e6bf6") #t
procedure
(uuid-string->symbol uuid) → uuid-symbol?
uuid : uuid-string?
> (uuid-string->symbol "f81d4fae-7dec-11d0-a765-00a0c91e6bf6") 'f81d4fae-7dec-11d0-a765-00a0c91e6bf6
> (uuid-string->symbol "F81D4FAE-7DEC-11D0-A765-00A0C91E6BF6") 'f81d4fae-7dec-11d0-a765-00a0c91e6bf6
> (uuid-string->symbol "f81D4fAE-7dec-11D0-A765-00a0C91e6bf6") 'f81d4fae-7dec-11d0-a765-00a0c91e6bf6