uuid:   Universally Unique Identifiers
uuid-symbol
uuid-string
strict-uuid-string?
uuid-symbol?
uuid-string?
uuid-string->symbol
8.12

uuid: Universally Unique Identifiers🔗ℹ

Philip McGrath <philip@philipmcgrath.com>

 (require uuid) package: uuid

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.

Returns a new, randomly-generated UUID as a symbol or string, respectively. The returned UUID is guaranteed to use lowercase characters for any hexidecimal digits from a to f, as specified by RFC 4122.

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.

Examples:
> (uuid-symbol)

'4fab2eda-22cb-4118-af13-d24d90af14fa

> (uuid-string)

"96729e2c-3ae0-4c71-89a1-0338a7901005"

procedure

(strict-uuid-string? v)  boolean?

  v : any/c
Recognizes UUIDs in canonical string form: that is, strings matching the regular expression:

#px"^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"

Examples:
> (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
Recognizes UUIDs represented as symbols. Equivalent to:
(λ (v)
  (and (symbol? v)
       (strict-uuid-string? (symbol->string v))))

Examples:
> (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
Like strict-uuid-string?, but case-insensitive.

Examples:
> (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?
Converts a UUID given as a string to a symbol. To ensure that equivalent UUID strings always produce eq? symbols, any upper-case hexidecimal digits in uuid are converted to lower-case.

Examples:
> (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