The UUID library¶
UUIDs are “Universally Unique IDentifiers”. They are immutable objects representing 128 bits of data.
In addition to constructing UUIDs from raw bytes or strings, it also provides for creating version 3, 4 or 5 UUIDs as defined in RFC 4122.
UUID creation functions:
The most common way of creating a UUID will likely be make-uuid4
to construct a random UUID.
The UUID module¶
-
<uuid>
Class¶ - Superclasses
<object>
- Init-Keywords
data (required) – An instance of
limited(<byte-vector>, size:, 16)
.
- Discussion
This class holds the data for a UUID. UUIDs are typically constructed with the functions
make-uuid3
,make-uuid4
, ormake-uuid5
.UUIDs can also be created from a string using
as(<uuid>, <string>)
.- See also
-
$nil-uuid
Constant¶ - Type
- Value
make(<uuid>, data: make(<byte-vector>, size: 16, fill: 0))
- Discussion
This is a UUID where all of the bits are
0
.
Creation¶
-
make-uuid3
Generic function¶ - Signature
make-uuid3 (namespace name) => (uuid)
- Parameters
namespace – An instance of
<uuid>
.name – An instance of
<string>
.
- Values
uuid – An instance of
<uuid>
.
- Discussion
Construct a version 3 UUID that is the MD5 hash of a namespace and name. Predefined namespaces are available as
$namespace-dns
,$namespace-url
,$namespace-iso-oid
, and$namespace-x500
.- Example
let uuid = make-uuid3($namespace-url, "http://github.com/dylan-foundry/uuid");
- See also
-
make-uuid4
Generic function¶ - Signature
make-uuid4 () => (uuid)
- Values
uuid – An instance of
<uuid>
.
- Discussion
Construct a version 4 UUID that uses random data.
- Example
let uuid = make-uuid4();
- See also
-
make-uuid5
Generic function¶ - Signature
make-uuid5 (namespace name) => (uuid)
- Parameters
namespace – An instance of
<uuid>
.name – An instance of
<string>
.
- Values
uuid – An instance of
<uuid>
.
- Discussion
Construct a version 5 UUID that is the SHA1 hash of a namespace and name. Predefined namespaces are available as
$namespace-dns
,$namespace-url
,$namespace-iso-oid
, and$namespace-x500
.- Example
let uuid = make-uuid5($namespace-dns, "opendylan.org");
- See also
Conversion¶
-
as(<uuid>, <string>)
Method¶ - Signature
as(<uuid>, string) => uuid
- Parameters
type – This must be
<uuid>
.string – An instance of
<string>
.
- Values
uuid – An instance of
<uuid>
.
- Discussion
Convert a string into a UUID. The string must only contain hexadecimal digits and, excluding dashes, must only 32 characters long.
- Example
let uuid = as(<uuid>, "4699DE5F-1F40-41B8-AB8D-55CCA1A6C9E9");
-
as(<string>, <uuid>)
Method¶ - Signature
as(<string>, uuid) => string
- Parameters
type – This must be
<string>
.uuid – An instance of
<uuid>
.
- Values
string – An instance of
<string>
.
- Discussion
Convert a UUID into a human readable string.
- Example
? as(<string>, uuid) => "4699DE5F-1F40-41B8-AB8D-55CCA1A6C9E9"
Miscellaneous¶
-
$namespace-dns
Constant¶ - Type
- Value
as(<uuid>, "6ba7b810-9dad-11d1-80b4-00c04fd430c8")
- Discussion
A predefined namespace UUID that can be used with
make-uuid3
ormake-uuid5
. This namespace UUID is as it is specified in RFC 4122.When used to create a UUID, the associated name should be a fully qualified domain name.
- See also
-
$namespace-iso-oid
Constant¶ - Type
- Value
as(<uuid>, "6ba7b812-9dad-11d1-80b4-00c04fd430c8")
- Discussion
A predefined namespace UUID that can be used with
make-uuid3
ormake-uuid5
. This namespace UUID is as it is specified in RFC 4122.When used to create a UUID, the associated name should be an ISO OID.
- See also
-
$namespace-url
Constant¶ - Type
- Value
as(<uuid>, "6ba7b811-9dad-11d1-80b4-00c04fd430c8")
- Discussion
A predefined namespace UUID that can be used with
make-uuid3
ormake-uuid5
. This namespace UUID is as it is specified in RFC 4122.When used to create a UUID, the associated name should be a URL.
- See also
-
$namespace-x500
Constant¶ - Type
- Value
as(<uuid>, "6ba7b814-9dad-11d1-80b4-00c04fd430c8")
- Discussion
A predefined namespace UUID that can be used with
make-uuid3
ormake-uuid5
. This namespace UUID is as it is specified in RFC 4122.When used to create a UUID, the associated name should be an X.500 DN in DER or a text output format.
- See also
-
rfc4122-variant?
Generic function¶
-
rfc4122-version
Generic function¶ - Signature
rfc4122-version (uuid) => (res)
- Parameters
uuid – An instance of
<uuid>
.
- Values
res – An instance of
<integer>
.
- Discussion
If the given uuid is one of the variants defined in RFC 4122, this will return which version it is.
If the uuid is not a variant from RFC 4122, the results of this function are undefined.
- Example
? let uuid = make-uuid4(); ? rfc4122-version(uuid) => 4