nustack
ReferenceNucore

access

Access atoms: Python's item and attribute management.

Module nu.core.access.

Access atoms: Python's item and attribute management.

Maps Python's member-access builtins and operators onto Nu - getting, setting, and deleting an item or attribute of a plain Python value. Every atom here is a ScalarQuery: a read yields the member, a write/delete mutates the value in-place and yields it back. This is local Python mutation off a value, not a fabric write - writing into a Ref's fabric location is the fabric's own interaction (context.Set / context.Delete and the like), which lives in the fabric dirs, never here. core is the pure Python builtins.

Builtins / operators to cover (Python -> Nu):

  • items (read): x[k] -> GetItem, len -> Len, in -> Contains, slice / x[a:b] -> Slice
  • items (write): x[k] = v -> SetItem, del x[k] -> DelItem
  • attrs (read): getattr -> GetAttr, hasattr -> HasAttr
  • attrs (write): setattr -> SetAttr, delattr -> DelAttr

Every atom is EVALUABLE: each defines compile (sync hot path) and acompile (async hot path) returning a thunk that computes from its child values, with inlined EMPTY / INVALID sentinel propagation (mirroring nu.core.arithmetic). The writes apply Python's x[k]=v / setattr / del to the object value and return that object so they compose. If a remove-and-return variant is wanted (pop-style), that is an Action - note it, but the builtins here are plain get/set/del.

NameSortCallMeaning
Containsscalar_queryContains(container, item)Containment: item in container.
DelAttrscalar_commandDelAttr(obj, name)Attribute delete: delattr(obj, name).
DelItemscalar_commandDelItem(target, key)Subscript delete: del x[k].
GetAttrscalar_queryGetAttr(obj, name, default)Attribute read: getattr(obj, name[, default]).
GetItemscalar_queryGetItem(target, key)Subscript access: x[k].
HasAttrscalar_queryHasAttr(obj, name)Attribute presence: hasattr(obj, name).
Lenscalar_queryLen(value)Length: len(x) of its one child.
SetAttrscalar_commandSetAttr(obj, name, value)Attribute write: setattr(obj, name, value).
SetItemscalar_commandSetItem(target, key, value)Subscript write: x[k] = v.
Slicescalar_querySlice(start, stop, step)The slice(...) builtin: builds a slice object.

Contains

Containment: item in container.

Contains(container, item)

Path nu.core.Contains. Kind ScalarQuery, sort scalar_query, cardinality scalar. Arity 2 (2 required).

Arguments

NameTypeDefaultMeaning
containerthe object to search.
itemthe value to look for.

Yields

True or False. INVALID when either child is EMPTY or INVALID.

Example

nu.run(nu.Contains(nu.Literal([1, 2, 3]), nu.Literal(9)))[0]
False

DelAttr

Attribute delete: delattr(obj, name).

DelAttr(obj, name)

Path nu.core.DelAttr. Kind Command, sort scalar_command, cardinality void. Arity 2 (2 required).

Arguments

NameTypeDefaultMeaning
objthe object to mutate. Slot 0, so it must hold a Ref.
namethe attribute name to remove.

Yields

Nothing.

Notes

  • Mutates the object in place and yields nothing.
  • A sentinel on either child bails out before mutating, the object is left untouched.
  • A missing attribute raises Python's own AttributeError, it does not bail silently.

Undocumented: example.

DelItem

Subscript delete: del x[k].

DelItem(target, key)

Path nu.core.DelItem. Kind Command, sort scalar_command, cardinality void. Arity 2 (2 required).

Arguments

NameTypeDefaultMeaning
targetthe container to mutate. Slot 0, so it must hold a Ref.
keythe index or key to remove.

Yields

Nothing.

Notes

  • Mutates the container in place and yields nothing.
  • A sentinel on either child bails out before mutating, the container is left untouched.
  • A missing key raises Python's own KeyError / IndexError, it does not bail silently.

Undocumented: example.

GetAttr

Attribute read: getattr(obj, name[, default]).

GetAttr(obj, name, default)

Path nu.core.GetAttr. Kind ScalarQuery, sort scalar_query, cardinality scalar. Arity 3 (3 required).

Arguments

NameTypeDefaultMeaning
objthe object to read from.
namethe attribute name.
defaultvalue to return when the attribute is absent. Optional: leave the child out entirely to let a missing attribute raise.

Yields

The attribute value. INVALID when obj, name, or (if given) default is EMPTY or INVALID.

Notes

  • Without a default child, a missing attribute raises Python's own AttributeError, it is not folded into EMPTY.

Example

nu.run(nu.GetAttr(nu.Literal(1j), nu.Literal("imag")))[0]
1.0

GetItem

Subscript access: x[k].

GetItem(target, key)

Path nu.core.GetItem. Kind ScalarQuery, sort scalar_query, cardinality scalar. Arity 2 (2 required).

Arguments

NameTypeDefaultMeaning
targetthe object to index.
keythe index or key to look up.

Yields

The member at that key. INVALID when either child is EMPTY or INVALID.

Notes

  • A missing key or out-of-range index raises Python's own KeyError / IndexError, it is not folded into EMPTY.

Example

nu.run(nu.GetItem(nu.Literal([10, 20, 30]), nu.Literal(1)))[0]
20

HasAttr

Attribute presence: hasattr(obj, name).

HasAttr(obj, name)

Path nu.core.HasAttr. Kind ScalarQuery, sort scalar_query, cardinality scalar. Arity 2 (2 required).

Arguments

NameTypeDefaultMeaning
objthe object to check.
namethe attribute name.

Yields

True or False. INVALID when either child is EMPTY or INVALID.

Example

nu.run(nu.HasAttr(nu.Literal(1j), nu.Literal("imag")))[0]
True

Len

Length: len(x) of its one child.

Len(value)

Path nu.core.Len. Kind ScalarQuery, sort scalar_query, cardinality scalar. Arity 1 (1 required).

Arguments

NameTypeDefaultMeaning
valuethe object to measure.

Yields

The length. INVALID when the child is EMPTY or INVALID.

Example

nu.run(nu.Len(nu.Literal("abcd")))[0]
4

SetAttr

Attribute write: setattr(obj, name, value).

SetAttr(obj, name, value)

Path nu.core.SetAttr. Kind Command, sort scalar_command, cardinality void. Arity 3 (3 required).

Arguments

NameTypeDefaultMeaning
objthe object to mutate. Slot 0, so it must hold a Ref.
namethe attribute name.
valuethe value to store.

Yields

Nothing.

Notes

  • Mutates the object in place and yields nothing, matching Python's setattr.
  • A sentinel on any child bails out before mutating, the object is left untouched.

Undocumented: example.

SetItem

Subscript write: x[k] = v.

SetItem(target, key, value)

Path nu.core.SetItem. Kind Command, sort scalar_command, cardinality void. Arity 3 (3 required).

Arguments

NameTypeDefaultMeaning
targetthe container to mutate. Slot 0, so it must hold a Ref.
keythe index or key to write to.
valuethe value to store.

Yields

Nothing.

Notes

  • Mutates the container in place and yields nothing, matching Python's x[k] = v.
  • A sentinel on any child bails out before mutating, the container is left untouched.

Undocumented: example.

Slice

The slice(...) builtin: builds a slice object.

Slice(start, stop, step)

Path nu.core.Slice. Kind ScalarQuery, sort scalar_query, cardinality scalar. Arity 3 (3 required).

Arguments

NameTypeDefaultMeaning
startthe start index, or None for the beginning.
stopthe stop index, or None for the end.
stepthe step, or None for 1.

Yields

A slice object. INVALID when any child is EMPTY or INVALID.

Example

nu.run(nu.Slice(nu.Literal(1), nu.Literal(3), nu.Literal(None)))[0]
slice(1, 3, None)

On this page