record
Records are similar to dicts but support only symbol and integer keys. They allow direct field access with dot syntax.
record Constructor
Constructs a record verbatim from all arguments, with positional arguments
receiving incrementing integer keys starting from 0 and key arguments
becoming fields. Order and key multiplicity are preserved.
Field Access
Records support direct dot-syntax for symbol keys:
And indexing for both symbol and integer keys:
Ordering and Multi-Map
Like dicts, records preserve insertion order and support multi-map semantics where applicable.
Iteration
Records are iterable, yielding [key, value] pairs:
Unpacking
Records support destructuring like dicts:
Type Methods
For programmatic access, the record type object provides methods. These are
called on the type, not on instances, as the instance field namespace is
entirely reserved for the user.
record.len rec
Returns the number of fields.
Returns: int
record.clear rec
Clears all fields.
record.insert rec key value
Sets a field. Key must be a symbol or integer.
record.get rec key :instance? :default? :else?
Gets a field value with optional default. Supports instance: for multi-map
access. Negative instance: indexes count from the end.
record.pop rec key :instance? :default? :else?
Removes and returns a value for a field. Supports instance: for multi-map
access to remove a specific value by its position among values for that field.
Negative instance: indexes count from the end.
record.delete rec key
Removes all values for a field.
Returns bool indicating whether any values were removed.
record.keys rec
Returns an iterator of keys. Each distinct key is yielded exactly once, in the order its first pair was inserted.
If duplicate-key iteration is needed, use ordinary record iteration.
record.values rec key?
Returns an iterator of values. With no key, it yields all stored values in
pair insertion order. With a key, it yields only the values associated with
that key, in that key's insertion order.
Missing keys return an empty iterator.
record.count rec key?
Returns a count derived from the record's multi-map structure.
With no key, it returns the number of distinct keys. With a key, it returns
the number of values associated with that key.
Missing keys return 0.
record.contains rec key value?
Tests whether the record contains the given key. If a value is provided, tests whether any value associated with that key matches.
Parameters:
| Name | Type | Description |
|---|---|---|
rec |
record |
the record to check |
key |
int or sym |
the key to check |
value |
optional value to check for (multi-map) |
Returns: bool