Atom

set()

Update an array slot

Set an index that already exists.

Atom
items = [3]
set(items, 0, 8)
print(items[0])
Output
8

The array is modified in place. Use add() to insert instead.

Store a new key

Give set() a dictionary, a key, and a value.

Atom
values = {}
set(values, 'name', 'Ada')
print(values.name)
Output
Ada

The dictionary now contains the name key.

Write into a packed byte slot

A packed slot keeps its declared representation.

Atom
bytes = create(u8, 1)
set(bytes, 0, 42)
print(type(bytes[0]) == u8)
Output
true

The stored value is converted to u8. Conversion fails if it does not fit.

Use 'set' when you have a collection, a key or index, and a replacement value.

Arrays and dictionaries

An array index must already exist. A dictionary key may be new. A hybrid table can extend its dense sequence at the next index or store a sparse key.

Packed data

Atom converts a compatible scalar to the field’s representation before writing it. The return value is the value passed to 'set', even when the stored representation changes. Text is immutable.

See get to read a value and add to append or insert.

Sets an element or field.

Signature

set(collection, key, value)

Parameters

Mutable ordinary collection or packed value, an appropriate key, and a replacement value.

Returns

The input replacement, even when storage coerces a packed scalar.

Behavior

Mutates the receiver. An array key selects an existing index. A hybrid can extend or store a sparse key. Packed assignment writes converted bytes.

Errors

Out-of-bounds array/packed index, invalid key or layout, failed scalar conversion, or read-only receiver.

Example

Atom
a = [0]
assert(set(a, 0, 9) == 9 and a[0] == 9)